home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / Python / _pdapilot.c next >
C/C++ Source or Header  |  1997-08-08  |  72KB  |  3,191 lines

  1. #include "Python.h"
  2. #include "pi-source.h"
  3. #include "pi-dlp.h"
  4. #include "pi-file.h"
  5. #include "pi-mail.h"
  6. #include "pi-memo.h"
  7. #include "pi-todo.h"
  8. #include "pi-socket.h"
  9. #include "pi-syspkt.h"
  10.  
  11. extern char * printlong (unsigned long val);
  12. extern unsigned long makelong (char * c);
  13.  
  14. static PyObject * Error;
  15.  
  16. static PyObject * DBClasses;
  17. static PyObject * PrefClasses;
  18.  
  19. static PyMethodDef PiFile_methods[];
  20.  
  21. static PyMethodDef Dlp_methods[];
  22.  
  23. static PyMethodDef DlpDB_methods[];
  24.  
  25. typedef struct {
  26.     PyObject_HEAD
  27.     struct pi_file    *pf;
  28.     
  29.     PyObject *Class;
  30. } PiFileObject;
  31.  
  32. staticforward PyTypeObject PiFile_Type;
  33.  
  34. #define PiFileObject_Check(v) ((v)->ob_type == &PiFile_Type)
  35.  
  36. typedef struct {
  37.     PyObject_HEAD
  38.  
  39.     struct RPC_params * p;
  40. } RpcObject;
  41.  
  42. staticforward PyTypeObject Rpc_Type;
  43.  
  44. #define RpcObject_Check(v) ((v)->ob_type == &Rpc_Type)
  45.  
  46. typedef struct {
  47.     PyObject_HEAD
  48.     void * buffer;
  49.     int socket;
  50. } DlpObject;
  51.  
  52. typedef struct {
  53.     PyObject_HEAD
  54.     DlpObject * socket;
  55.     int handle;
  56.     
  57.     PyObject * dbname;
  58.     int dbmode;
  59.     int dbcard;
  60.     
  61.     PyObject *Class;
  62. } DlpDBObject;
  63.  
  64. staticforward PyTypeObject Dlp_Type;
  65.  
  66. #define DlpObject_Check(v) ((v)->ob_type == &Dlp_Type)
  67.  
  68. staticforward PyTypeObject DlpDB_Type;
  69.  
  70. #define DlpDBObject_Check(v) ((v)->ob_type == &DlpDB_Type)
  71.  
  72. static void
  73. PiFile_dealloc(self)
  74.     PiFileObject *self;
  75. {
  76.     Py_XDECREF(self->Class);
  77.     if (self->pf)
  78.         pi_file_close(self->pf);
  79.     PyMem_DEL(self);
  80. }
  81.  
  82. static void
  83. Rpc_dealloc(self)
  84.     RpcObject *self;
  85. {
  86.     if (self->p)
  87.         free(self->p);
  88.     PyMem_DEL(self);
  89. }
  90.  
  91. static void
  92. Dlp_dealloc(self)
  93.     DlpObject *self;
  94. {
  95.     if (self->buffer)
  96.         free(self->buffer);
  97.     if (self->socket)
  98.         pi_close(self->socket);
  99.     PyMem_DEL(self);
  100. }
  101.  
  102. static void
  103. DlpDB_dealloc(self)
  104.     DlpDBObject *self;
  105. {
  106.     Py_XDECREF(self->Class);
  107.     if (self->handle)
  108.         dlp_CloseDB(self->socket->socket, self->handle);
  109.     if (self->socket)
  110.         Py_DECREF(self->socket);
  111.     if (self->dbname)
  112.         Py_DECREF(self->dbname);
  113.     PyMem_DEL(self);
  114. }
  115.  
  116. static PyObject *
  117. PiFile_getattr(self, name)
  118.     PiFileObject * self;
  119.     char * name;
  120. {
  121.     if ((name[0] == 'C') && (strcmp(name, "Class")==0)) {
  122.         Py_INCREF(self->Class);
  123.         return self->Class;
  124.     }
  125.     return Py_FindMethod(PiFile_methods, (PyObject *)self, name);
  126. }
  127.  
  128. int
  129. PiFile_setattr(self, name, v)
  130.     PiFileObject * self;
  131.     char * name;
  132.     PyObject * v;
  133. {
  134.     if ((name[0] == 'C') && (strcmp(name, "Class")==0)) {
  135.         if (!v)  {
  136.             PyErr_SetString(PyExc_AttributeError,
  137.                 "class attribute may not be deleted");
  138.             return -1;
  139.         }
  140.         Py_DECREF(self->Class);
  141.         self->Class = v;
  142.         Py_INCREF(self->Class);
  143.         return 0;
  144.     }
  145.     PyErr_SetString(PyExc_AttributeError,
  146.         "attribute not settable");
  147.     return -1;
  148. }
  149.  
  150.  
  151. staticforward PyTypeObject PiFile_Type = {
  152.         PyObject_HEAD_INIT(&PyType_Type)
  153.         0,            /*ob_size*/
  154.         "pdapilot.file",        /*tp_name*/
  155.     sizeof(PiFileObject),    /*tp_basicsize*/
  156.         0,            /*tp_itemsize*/
  157.                 /* methods */
  158.     (destructor)PiFile_dealloc,    /*tp_dealloc*/
  159.     0,            /*tp_print*/
  160.     (getattrfunc)PiFile_getattr,    /*tp_getattr*/
  161.     (setattrfunc)PiFile_setattr,    /*tp_setattr*/
  162.     0,            /*tp_compare*/
  163.     0,            /*tp_repr*/
  164.     0,            /*tp_as_number*/
  165.     0,            /*tp_as_sequence*/
  166.     0,            /*tp_as_mapping*/
  167.     0,            /*tp_hash*/
  168. };
  169.  
  170. staticforward PyTypeObject Rpc_Type = {
  171.         PyObject_HEAD_INIT(&PyType_Type)
  172.         0,            /*ob_size*/
  173.         "pdapilot.rpc",        /*tp_name*/
  174.     sizeof(RpcObject),    /*tp_basicsize*/
  175.         0,            /*tp_itemsize*/
  176.                 /* methods */
  177.     (destructor)Rpc_dealloc,    /*tp_dealloc*/
  178.     0,            /*tp_print*/
  179.     0,            /*tp_getattr*/
  180.     0,            /*tp_setattr*/
  181.     0,            /*tp_compare*/
  182.     0,            /*tp_repr*/
  183.     0,            /*tp_as_number*/
  184.     0,            /*tp_as_sequence*/
  185.     0,            /*tp_as_mapping*/
  186.     0,            /*tp_hash*/
  187. };
  188.  
  189. static PyObject *
  190. Dlp_getattr(self, name)
  191.     PyObject * self;
  192.     char * name;
  193. {
  194.     return Py_FindMethod(Dlp_methods, (PyObject *)self, name);
  195. }
  196.  
  197. staticforward PyTypeObject Dlp_Type = {
  198.     PyObject_HEAD_INIT(&PyType_Type)
  199.     0,            /*ob_size*/
  200.     "pdapilot.dlp",        /*tp_name*/
  201.     sizeof(DlpObject),    /*tp_basicsize*/
  202.     0,            /*tp_itemsize*/
  203.                 /* methods */
  204.     (destructor)Dlp_dealloc,    /*tp_dealloc*/
  205.     0,            /*tp_print*/
  206.     (getattrfunc)Dlp_getattr,    /*tp_getattr*/
  207.     0,            /*tp_setattr*/
  208.     0,            /*tp_compare*/
  209.     0,            /*tp_repr*/
  210.     0,            /*tp_as_number*/
  211.     0,            /*tp_as_sequence*/
  212.     0,            /*tp_as_mapping*/
  213.     0,            /*tp_hash*/
  214. };
  215.  
  216. static PyObject *
  217. DlpDB_getattr(self, name)
  218.     DlpDBObject * self;
  219.     char * name;
  220. {
  221.     if ((name[0] == 'C') && (strcmp(name, "Class")==0)) {
  222.         Py_INCREF(self->Class);
  223.         return self->Class;
  224.     }
  225.     return Py_FindMethod(DlpDB_methods, (PyObject *)self, name);
  226. }
  227.  
  228. int
  229. DlpDB_setattr(self, name, v)
  230.     DlpDBObject * self;
  231.     char * name;
  232.     PyObject * v;
  233. {
  234.     if ((name[0] == 'C') && (strcmp(name, "Class")==0)) {
  235.         if (!v)  {
  236.             PyErr_SetString(PyExc_AttributeError,
  237.                 "class attribute may not be deleted");
  238.             return -1;
  239.         }
  240.         Py_DECREF(self->Class);
  241.         self->Class = v;
  242.         Py_INCREF(self->Class);
  243.         return 0;
  244.     }
  245.     PyErr_SetString(PyExc_AttributeError,
  246.         "attribute not settable");
  247.     return -1;
  248. }
  249.  
  250. staticforward PyTypeObject DlpDB_Type = {
  251.     PyObject_HEAD_INIT(&PyType_Type)
  252.     0,            /*ob_size*/
  253.     "pdapilot.dlp.db",    /*tp_name*/
  254.     sizeof(DlpDBObject),    /*tp_basicsize*/
  255.     0,            /*tp_itemsize*/
  256.                 /* methods */
  257.     (destructor)DlpDB_dealloc,    /*tp_dealloc*/
  258.     0,            /*tp_print*/
  259.     (getattrfunc)DlpDB_getattr,    /*tp_getattr*/
  260.     (setattrfunc)DlpDB_setattr,    /*tp_setattr*/
  261.     0,            /*tp_compare*/
  262.     0,            /*tp_repr*/
  263.     0,            /*tp_as_number*/
  264.     0,            /*tp_as_sequence*/
  265.     0,            /*tp_as_mapping*/
  266.     0,            /*tp_hash*/
  267. };
  268.  
  269. static PyObject *
  270. Socket(self, args)
  271.     PyObject *self;
  272.     PyObject *args;
  273. {
  274.     int domain,type,protocol,result;
  275.     if (!PyArg_ParseTuple(args, "iii", &domain,&type,&protocol))
  276.         return NULL;
  277.     result = pi_socket(domain,type,protocol);
  278.     if (result==-1) {
  279.         PyErr_SetFromErrno(Error);
  280.         return NULL;
  281.     } else
  282.         return Py_BuildValue("i", result);
  283. }
  284.  
  285. static PyObject *
  286. CloseSocket(self, args)
  287.     PyObject *self;
  288.     PyObject *args;
  289. {
  290.     int socket,result;
  291.     if (!PyArg_ParseTuple(args, "i", &socket))
  292.         return NULL;
  293.     result = pi_close(socket);
  294.     if (result==-1) {
  295.         PyErr_SetFromErrno(Error);
  296.         return NULL;
  297.     } else
  298.         return Py_BuildValue("i", result);
  299. }
  300.  
  301. static PyObject *
  302. Read(self, args)
  303.     PyObject *self;
  304.     PyObject *args;
  305. {
  306.     int length,socket,result;
  307.     char * data;
  308.     if (!PyArg_ParseTuple(args, "is#", &socket, &data, &length))
  309.         return NULL;
  310.     result = pi_read(socket,data,length);
  311.     if (result==-1) {
  312.         PyErr_SetFromErrno(Error);
  313.         return NULL;
  314.     } else
  315.         return Py_BuildValue("i", result);
  316. }
  317.  
  318. static PyObject *
  319. Write(self, args)
  320.     PyObject *self;
  321.     PyObject *args;
  322. {
  323.     int length,socket, result;
  324.     char * data;
  325.     if (!PyArg_ParseTuple(args, "is#", &socket, &data, &length))
  326.         return NULL;
  327.     result = pi_write(socket,data,length);
  328.     if (result==-1) {
  329.         PyErr_SetFromErrno(Error);
  330.         return NULL;
  331.     } else
  332.         return Py_BuildValue("i", result);
  333. }
  334.  
  335. static PyObject *
  336. Bind(self, args)
  337.     PyObject *self;
  338.     PyObject *args;
  339. {
  340.     PyObject * addr;
  341.     int socket;
  342.     struct pi_sockaddr * a;
  343.     int len,i;
  344.     if (!PyArg_ParseTuple(args, "iO", &socket, &addr))
  345.         return NULL;
  346.     if (PyString_Check(addr)) {
  347.         a = (struct pi_sockaddr *)PyString_AsString(addr);
  348.         len = PyString_Size(addr);
  349.         i = pi_bind(socket,(struct sockaddr*)a,len);
  350.     } else if (PyDict_Check(addr)) {
  351.         PyObject * e = PyDict_GetItemString(addr, "device");
  352.         if (e) {
  353.             len = PyString_Size(e)+sizeof(struct pi_sockaddr);
  354.             a = malloc(len);
  355.             strcpy(a->pi_device, PyString_AsString(e));
  356.             
  357.             e = PyDict_GetItemString(addr, "family");
  358.             a->pi_family = e ? PyInt_AsLong(e) : 0;
  359.             
  360.         }
  361.         i = pi_bind(socket,(struct sockaddr*)a,len);
  362.         free(a);
  363.     } else {
  364.         PyErr_SetString(Error, "second argument not string or dict");
  365.         return NULL;
  366.     }
  367.     if (i==-1) {
  368.         PyErr_SetFromErrno(Error);
  369.         return NULL;
  370.     } else
  371.         return Py_BuildValue("i", i);
  372. }
  373.  
  374. static PyObject *
  375. Listen(self, args)
  376.     PyObject *self;
  377.     PyObject *args;
  378. {
  379.     int socket,backlog=1,result;
  380.     if (!PyArg_ParseTuple(args, "i|i", &socket,&backlog))
  381.         return NULL;
  382.     result = pi_listen(socket,backlog);
  383.     if (result==-1) {
  384.         PyErr_SetFromErrno(Error);
  385.         return NULL;
  386.     } else
  387.         return Py_BuildValue("i", result);
  388. }
  389.  
  390. static PyObject *
  391. Accept(self, args)
  392.     PyObject *self;
  393.     PyObject *args;
  394. {
  395.     int socket;
  396.     int result;
  397.     if (!PyArg_ParseTuple(args, "i", &socket))
  398.         return NULL;
  399.     
  400.     result = pi_accept(socket,0,0);
  401.     
  402.     if (result>=0) {
  403.         DlpObject * obj = PyObject_NEW(DlpObject, &Dlp_Type);
  404.         obj->socket = result;
  405.         obj->buffer = malloc(0xffff);
  406.         return (PyObject*)obj;
  407.     } else {
  408.         PyErr_SetFromErrno(Error);
  409.         return NULL;
  410.     }
  411. }
  412.  
  413. static PyObject *
  414. OpenPort(self, args)
  415.     PyObject *self;
  416.     PyObject *args;
  417. {
  418.     char * port;
  419.     PyObject *a, *b, *c;
  420.     if (!PyArg_ParseTuple(args, "s", &port))
  421.         return NULL;
  422.     
  423.     a = Py_BuildValue("(iii)", PI_AF_SLP, PI_SOCK_STREAM, PI_PF_PADP);
  424.     b = Socket(self, a);
  425.     Py_DECREF(a);
  426.     if (!b)
  427.         return NULL;
  428.     a = Py_BuildValue("(O{siss})", b, "family", PI_AF_SLP, "device", port);
  429.     c = Bind(self, a);
  430.     Py_DECREF(a);
  431.     if (!c)
  432.         return NULL;
  433.     a = Py_BuildValue("(Oi)", b, 1);
  434.     c = Listen(self, a);
  435.     Py_DECREF(a);
  436.     if (!c)
  437.         return NULL;
  438.     
  439.     return b;
  440. }
  441.  
  442. static int
  443. ParseTm(o, v)
  444.     PyObject * o;
  445.     void *v;
  446. {
  447.     struct tm * t = v;
  448.     
  449.     if (!PyArg_ParseTuple(o, "iiiiiiiii", 
  450.         &t->tm_year, 
  451.         &t->tm_mon,
  452.         &t->tm_mday,
  453.         &t->tm_hour,
  454.         &t->tm_min,
  455.         &t->tm_sec,
  456.         &t->tm_wday,
  457.         &t->tm_yday,
  458.         &t->tm_isdst))
  459.         return 0;
  460.     t->tm_year-=1900;
  461.     t->tm_mon--;
  462.     t->tm_wday = (t->tm_wday+8)%7;
  463.     t->tm_yday--;
  464.     
  465.     return 1;
  466. }
  467.  
  468. static PyObject *
  469. BuildTm(v)
  470.     void *v;
  471. {
  472.     struct tm * t = v;
  473.     
  474.     /* Obey the rules used by Python's timemodule */
  475.     
  476.     return Py_BuildValue("(iiiiiiiii)",
  477.         t->tm_year+1900,
  478.         t->tm_mon+1,
  479.         t->tm_mday,
  480.         t->tm_hour,
  481.         t->tm_min,
  482.         t->tm_sec,
  483.         (t->tm_wday+6)%7,
  484.         t->tm_yday+1,
  485.         t->tm_isdst);
  486. }
  487.  
  488. static int
  489. ParseChar4(o, v)
  490.     PyObject * o;
  491.     void *v;
  492. {
  493.     if (PyString_Check(o)) {
  494.         if (PyString_Size(o) != 4) {
  495.             PyErr_SetString(Error, "code string is not four bytes long");
  496.             return 0;
  497.         }
  498.         *(unsigned long*)v = makelong(PyString_AsString(o));
  499.     } else if (PyInt_Check(o)) {
  500.         *(unsigned long*)v = PyInt_AsLong(o);
  501.     } else {
  502.         PyErr_SetString(Error, "code is not string or int");
  503.         return 0;
  504.     }
  505.     return 1;
  506. }
  507.  
  508. static PyObject *
  509. BuildChar4(v)
  510.     void *v;
  511. {
  512.     char * l = printlong(*(unsigned long*)v);
  513.     if (    (isalpha(l[0]) || (l[0] == ' ') || (l[0] == '_')) &&
  514.         (isalpha(l[1]) || (l[1] == ' ') || (l[1] == '_')) &&
  515.         (isalpha(l[2]) || (l[2] == ' ') || (l[2] == '_')) &&
  516.         (isalpha(l[3]) || (l[3] == ' ') || (l[3] == '_')))
  517.         return PyString_FromString(l);
  518.     else
  519.         return PyInt_FromLong(*(unsigned long*)v);
  520. }
  521.  
  522. #define Dlp_CheckError(x)     \
  523.     if ((x)<0) {     \
  524.         PyErr_SetString(Error, dlp_strerror((x)));     \
  525.         return NULL;    \
  526.     } else ;
  527.  
  528. #define DlpDB_CheckError(x)             \
  529.     if ((x)<0) {                 \
  530.         if ((x)==-5) {            \
  531.             Py_INCREF(Py_None);    \
  532.             return Py_None;        \
  533.         } else {            \
  534.             PyErr_SetString(Error, dlp_strerror((x)));     \
  535.             return NULL;        \
  536.         }                \
  537.     } else ;
  538.  
  539. static PyObject *
  540. ResetSystem(self, args)
  541.     DlpObject *self;
  542.     PyObject *args;
  543. {
  544.     int socket, result;
  545.     if (!PyArg_ParseTuple(args, ""))
  546.         return NULL;
  547.     result = dlp_ResetSystem(self->socket);
  548.     Dlp_CheckError(result);
  549.     return Py_BuildValue("i", result);
  550. }
  551.  
  552. static PyObject *
  553. Dirty(self, args)
  554.     DlpObject *self;
  555.     PyObject *args;
  556. {
  557.     int socket, result;
  558.     if (!PyArg_ParseTuple(args, ""))
  559.         return NULL;
  560.     result = dlp_ResetLastSyncPC(self->socket);
  561.     Dlp_CheckError(result);
  562.     return Py_BuildValue("i", result);
  563. }
  564.  
  565. static PyObject *
  566. OpenDB(self, args)
  567.     DlpObject *self;
  568.     PyObject *args;
  569. {
  570.     int mode = dlpOpenReadWrite, cardno = 0;
  571.     char * name;
  572.     int result, handle, raw = 0;
  573.     PyObject * packer;
  574.     DlpDBObject * obj;
  575.     if (!PyArg_ParseTuple(args, "s|iii", &name, &mode, &cardno, &raw))
  576.         return NULL;
  577.  
  578.     result = dlp_OpenDB(self->socket, cardno, mode, name, &handle);
  579.     
  580.     Dlp_CheckError(result);
  581.     
  582.     obj = PyObject_NEW(DlpDBObject, &DlpDB_Type);
  583.     obj->socket = self;
  584.     obj->handle = handle;
  585.     obj->dbcard = cardno;
  586.     obj->dbmode = mode;
  587.     obj->dbname = PyTuple_GetItem(args,0);
  588.     Py_INCREF(obj->dbname);
  589.     Py_INCREF(self);
  590.     
  591.     obj->Class = 0;
  592.     packer = PyDict_GetItemString(DBClasses, name);
  593.     if (!packer)
  594.         packer = PyDict_GetItemString(DBClasses, "");
  595.     if (!packer) {
  596.         PyErr_SetString(PyExc_ValueError, "pdapilot.DBClasses must contain a default");
  597.         dlp_CloseDB(self->socket, handle);
  598.         free(obj);
  599.         return NULL;
  600.     }
  601.     if (packer) {
  602.         obj->Class = packer;
  603.         Py_XINCREF(packer);
  604.     }
  605.     
  606.     return (PyObject*)obj;
  607. }
  608.  
  609. static PyObject *
  610. CreateDB(self, args)
  611.     DlpObject *self;
  612.     PyObject *args;
  613. {
  614.     char * name;
  615.     long creator, type;
  616.     int cardno=0, flags, version=1;
  617.     int raw=0;
  618.     int result;
  619.     int handle;
  620.     DlpDBObject * obj;
  621.     PyObject * packer;
  622.     if (!PyArg_ParseTuple(args, "sO&li|iii", &name, &ParseChar4, &creator, &type, &flags, &version, &cardno, &raw))
  623.         return NULL;
  624.  
  625.     result = dlp_CreateDB(self->socket, creator, type, cardno, 
  626.         flags, version, name, &handle);
  627.  
  628.     Dlp_CheckError(result);
  629.     
  630.     obj = PyObject_NEW(DlpDBObject, &DlpDB_Type);
  631.     obj->socket = self;
  632.     obj->handle = handle;
  633.     obj->dbname = PyTuple_GetItem(args, 0);
  634.     Py_INCREF(obj->dbname);
  635.     obj->dbmode = dlpOpenRead|dlpOpenWrite|dlpOpenSecret;
  636.     obj->dbcard = cardno;
  637.     Py_INCREF(self);
  638.  
  639.     /*obj->Pack = obj->Unpack = obj->PackAppBlock = obj->UnpackAppBlock = 
  640.         obj->PackSortBlock = obj->UnpackSortBlock = 0;*/
  641.     obj->Class = 0;
  642.     packer = PyDict_GetItemString(DBClasses, name);
  643.     if (!packer)
  644.         packer = PyDict_GetItemString(DBClasses, "");
  645.     if (!packer) {
  646.         PyErr_SetString(PyExc_ValueError, "pdapilot.DBClasses must contain a default");
  647.         dlp_CloseDB(self->socket, handle);
  648.         free(obj);
  649.         return NULL;
  650.     }
  651.     if (packer) {
  652.         obj->Class = packer;
  653.         Py_XINCREF(packer);
  654.     }
  655.     /*packer = PyDict_GetItemString(DBPackers, name);
  656.     if (packer && PyTuple_Check(packer)) {
  657.         PyArg_ParseTuple(packer, "|OOOOOO",
  658.             &obj->Unpack, &obj->Pack,
  659.             &obj->UnpackAppBlock, &obj->PackAppBlock,
  660.             &obj->UnpackSortBlock, &obj->PackSortBlock);
  661.         Py_XINCREF(obj->Pack);
  662.         Py_XINCREF(obj->Unpack);
  663.         Py_XINCREF(obj->PackAppBlock);
  664.         Py_XINCREF(obj->UnpackAppBlock);
  665.         Py_XINCREF(obj->PackSortBlock);
  666.         Py_XINCREF(obj->UnpackSortBlock);
  667.     }*/
  668.  
  669.     return (PyObject*)obj;
  670. }
  671.  
  672. static PyObject *
  673. CloseDB(self, args)
  674.     DlpDBObject *self;
  675.     PyObject *args;
  676. {
  677.     if (!PyArg_ParseTuple(args, ""))
  678.         return NULL;
  679.     
  680.     if (self->handle) {
  681.         int result = dlp_CloseDB(self->socket->socket, self->handle);
  682.         self->handle = 0;        
  683.         Dlp_CheckError(result);
  684.     }
  685.     
  686.     Py_INCREF(Py_None);
  687.     return Py_None;
  688. }
  689.  
  690. static PyObject *
  691. DeleteRsc(self, args)
  692.     DlpDBObject *self;
  693.     PyObject *args;
  694. {
  695.     unsigned long type;
  696.     int id, result;
  697.     
  698.     if (!PyArg_ParseTuple(args, "O&i", &ParseChar4, &type, &id))
  699.         return NULL;
  700.  
  701.     result = dlp_DeleteResource(self->socket->socket, self->handle, 0, type, id);
  702.  
  703.     Dlp_CheckError(result);
  704.  
  705.     return Py_BuildValue("i", result);
  706. }
  707.  
  708. static PyObject *
  709. DeleteAllRsc(self, args)
  710.     DlpDBObject *self;
  711.     PyObject *args;
  712. {
  713.     int result;
  714.     if (!PyArg_ParseTuple(args, ""))
  715.         return NULL;
  716.     
  717.     result = dlp_DeleteResource(self->socket->socket, self->handle, 1, 0, 0);
  718.     
  719.     Dlp_CheckError(result);
  720.     
  721.     return Py_BuildValue("i", result);
  722. }
  723.  
  724. static PyObject *
  725. DeleteRec(self, args)
  726.     DlpDBObject *self;
  727.     PyObject *args;
  728. {
  729.     unsigned long id;
  730.     int result;
  731.     
  732.     if (!PyArg_ParseTuple(args, "l", &id))
  733.         return NULL;
  734.  
  735.     result = dlp_DeleteRecord(self->socket->socket, self->handle, 0, id);
  736.     
  737.     Dlp_CheckError(result);
  738.     
  739.     return Py_BuildValue("i", result);
  740. }
  741.  
  742. static PyObject *
  743. DeleteAllRec(self, args)
  744.     DlpDBObject *self;
  745.     PyObject *args;
  746. {
  747.     int result;
  748.     if (!PyArg_ParseTuple(args, ""))
  749.         return NULL;
  750.         
  751.     result = dlp_DeleteRecord(self->socket->socket, self->handle, 1, 0);
  752.     
  753.     Dlp_CheckError(result);
  754.     
  755.     return Py_BuildValue("i", result);
  756. }
  757.  
  758. static PyObject *
  759. NextModRec(self, args)
  760.     DlpDBObject *self;
  761.     PyObject *args;
  762. {
  763.     unsigned long id;
  764.     int index, length, attr, category=-1;
  765.     int result;
  766.     PyObject * ret, *c, *callargs;
  767.     if (!PyArg_ParseTuple(args, "|i", &category))
  768.         return NULL;
  769.     
  770.     if (category == -1)
  771.         result = dlp_ReadNextModifiedRec(self->socket->socket, self->handle, self->socket->buffer, &id, &index, &length, &attr, &category);
  772.     else
  773.         result = dlp_ReadNextModifiedRecInCategory(self->socket->socket, self->handle, index, self->socket->buffer, &id, &index, &length, &attr);
  774.     
  775.     DlpDB_CheckError(result);
  776.     
  777.     c = PyObject_GetAttrString(self->Class, "Record");
  778.     callargs = Py_BuildValue("(s#Oilii)", self->socket->buffer, result, self, index, (long)id, attr, category);
  779.     ret = PyEval_CallObject(c, callargs);
  780.     Py_DECREF(callargs);
  781.     return ret;
  782. }
  783.  
  784. static PyObject *
  785. NextCatRec(self, args)
  786.     DlpDBObject *self;
  787.     PyObject *args;
  788. {
  789.     unsigned long id;
  790.     int index, length, attr, category;
  791.     int result;
  792.     PyObject * ret, *callargs, *c;
  793.     if (!PyArg_ParseTuple(args, "i", &category))
  794.         return NULL;
  795.     
  796.     result = dlp_ReadNextRecInCategory(self->socket->socket, self->handle, index, self->socket->buffer, &id, &index, &length, &attr);
  797.     
  798.     DlpDB_CheckError(result);
  799.  
  800.     c = PyObject_GetAttrString(self->Class, "Record");
  801.     callargs = Py_BuildValue("(s#Oilii)", self->socket->buffer, result, self, index, (long)id, attr, category);
  802.     ret = PyEval_CallObject(c, callargs);
  803.     Py_DECREF(callargs);
  804.     return ret;
  805. }
  806.  
  807. static PyObject *
  808. GetRec(self, args)
  809.     DlpDBObject *self;
  810.     PyObject *args;
  811. {
  812.     unsigned long id;
  813.     int index, length, attr, category;
  814.     int result;
  815.     PyObject * ret, *c, *callargs;
  816.     if (!PyArg_ParseTuple(args, "i", &index))
  817.         return NULL;
  818.     
  819.     result = dlp_ReadRecordByIndex(self->socket->socket, self->handle, index, self->socket->buffer, &id, &length, &attr, &category);
  820.     
  821.     DlpDB_CheckError(result);
  822.     
  823.     c = PyObject_GetAttrString(self->Class, "Record");
  824.     callargs = Py_BuildValue("(s#Oilii)", self->socket->buffer, result, self, index, (long)id, attr, category);
  825.     ret = PyEval_CallObject(c, callargs);
  826.     Py_DECREF(callargs);
  827.     return ret;
  828. }
  829.  
  830. static PyObject *
  831. SetRec(self, args)
  832.     DlpDBObject *self;
  833.     PyObject *args;
  834. {
  835.     unsigned long id=0;
  836.     unsigned long newid;
  837.     int raw=0;
  838.     int index, length, attr=0, category=0;
  839.     char * data;
  840.     PyObject * h, *i;
  841.     int result;
  842.  
  843.     if (!PyArg_ParseTuple(args, "O|i", &h, &raw))
  844.         return NULL;
  845.     
  846.     if (raw) 
  847.         i = PyObject_GetAttrString(h, "raw");
  848.     else
  849.         i = PyObject_CallMethod(h, "pack", "O", self);
  850.     data = PyString_AsString(i);
  851.     length = PyString_Size(i);
  852.  
  853.     if (!(i=PyObject_GetAttrString(h, "id")))
  854.         { PyErr_SetString(PyExc_ValueError, "The record's .id attribute must be set");
  855.             return NULL; } 
  856.     else if (i == Py_None) 
  857.         id = 0;
  858.     else
  859.         id = PyInt_AsLong(i);
  860.     attr = 0;
  861.     if ((i=PyObject_GetAttrString(h, "deleted")) && PyInt_AsLong(i))
  862.         attr |= 0x80;
  863.     if ((i=PyObject_GetAttrString(h, "modified")) && PyInt_AsLong(i))
  864.         attr |= 0x40;
  865.     if ((i=PyObject_GetAttrString(h, "busy")) && PyInt_AsLong(i))
  866.         attr |= 0x20;
  867.     if ((i=PyObject_GetAttrString(h, "secret")) && PyInt_AsLong(i))
  868.         attr |= 0x10;
  869.     if ((i=PyObject_GetAttrString(h, "archived")) && PyInt_AsLong(i))
  870.         attr |= 0x08;
  871.     if (i=PyObject_GetAttrString(h, "category")) category = PyInt_AsLong(i);
  872.     
  873.     dlp_WriteRecord(self->socket->socket, self->handle, attr, id, category, data, length, &newid);
  874.     
  875.     DlpDB_CheckError(result);
  876.     
  877.     i = Py_BuildValue("l", (long)newid);
  878.     PyObject_SetAttrString(h, "id", i);
  879.     Py_INCREF(i);
  880.     
  881.     return i;
  882. }
  883.  
  884. static PyObject *
  885. SetRsc(self, args)
  886.     DlpDBObject *self;
  887.     PyObject *args;
  888. {
  889.     unsigned long type;
  890.     int id, length;
  891.     char * data;
  892.     int result;
  893.     PyObject *h, *i;
  894.     if (!PyArg_ParseTuple(args, "O", &h))
  895.         return NULL;
  896.         
  897.     i = PyObject_CallMethod(h, "pack", "O", self);
  898.     data = PyString_AsString(i);
  899.     length = PyString_Size(i);
  900.  
  901.     if (!(i=PyObject_GetAttrString(h, "id")) || (i == Py_None))
  902.         { PyErr_SetString(PyExc_ValueError, "The resource's .id attribute must be set"); 
  903.             return NULL; } 
  904.     else
  905.         id = PyInt_AsLong(i);
  906.     if (!(i=PyObject_GetAttrString(h, "type")) || (i == Py_None))
  907.         { PyErr_SetString(PyExc_ValueError, "The resource's .type attribute must be set"); 
  908.             return NULL; } 
  909.     else
  910.         type = ParseChar4(i);
  911.  
  912.     result = dlp_WriteResource(self->socket->socket, self->handle, type, id, data, length);
  913.  
  914.     DlpDB_CheckError(result);
  915.     
  916.     return Py_BuildValue("");
  917. }
  918.  
  919. static PyObject *
  920. GetRecById(self, args)
  921.     DlpDBObject *self;
  922.     PyObject *args;
  923. {
  924.     unsigned long id;
  925.     int index, result, length, attr, category;
  926.     PyObject *ret, *c, *callargs;
  927.     if (!PyArg_ParseTuple(args, "l", &id))
  928.         return NULL;
  929.     
  930.     result = dlp_ReadRecordById(self->socket->socket, self->handle, id, self->socket->buffer, &index, &length, &attr, &category);
  931.     
  932.     DlpDB_CheckError(result);
  933.  
  934.     c = PyObject_GetAttrString(self->Class, "Record");
  935.     callargs = Py_BuildValue("(s#Oilii)", self->socket->buffer, result, self, index, (long)id, attr, category);
  936.     ret = PyEval_CallObject(c, callargs);
  937.     Py_DECREF(callargs);
  938.     return ret;
  939. }
  940.  
  941. static PyObject *
  942. GetRsc(self, args)
  943.     DlpDBObject *self;
  944.     PyObject *args;
  945. {
  946.     unsigned long type;
  947.     int id, length, index;
  948.     int result;
  949.     PyObject *ret, *c, *callargs;
  950.     if (!PyArg_ParseTuple(args, "i", &index))
  951.         return NULL;
  952.     
  953.     result = dlp_ReadResourceByIndex(self->socket->socket, self->handle, index, self->socket->buffer, &type, &id, &length);
  954.     
  955.     DlpDB_CheckError(result);
  956.  
  957.     c = PyObject_GetAttrString(self->Class, "Resource");
  958.     callargs = Py_BuildValue("(s#OO&i)", self->socket->buffer, result, self, &BuildChar4, &type, id);
  959.     ret = PyEval_CallObject(c, callargs);
  960.     Py_DECREF(callargs);
  961.     return ret;
  962. }
  963.  
  964. static PyObject *
  965. GetRscById(self, args)
  966.     DlpDBObject *self;
  967.     PyObject *args;
  968. {
  969.     unsigned long type;
  970.     int id, length, index;
  971.     int result;
  972.     PyObject *ret, *c, *callargs;
  973.     if (!PyArg_ParseTuple(args, "O&i", &ParseChar4, &type, &id))
  974.         return NULL;
  975.     
  976.     result = dlp_ReadResourceByType(self->socket->socket, self->handle, type, id, self->socket->buffer, &index, &length);
  977.  
  978.     DlpDB_CheckError(result);    
  979.  
  980.     c = PyObject_GetAttrString(self->Class, "Resource");
  981.     callargs = Py_BuildValue("(s#OO&i)", self->socket->buffer, result, self, &BuildChar4, &type, id);
  982.     ret = PyEval_CallObject(c, callargs);
  983.     Py_DECREF(callargs);
  984.     return ret;
  985. }
  986.  
  987.  
  988. static PyObject *
  989. Records(self, args)
  990.     DlpDBObject *self;
  991.     PyObject *args;
  992. {
  993.     int records, result;
  994.     
  995.     if (!PyArg_ParseTuple(args, ""))
  996.         return NULL;
  997.     
  998.     result = dlp_ReadOpenDBInfo(self->socket->socket, self->handle, &records);
  999.     
  1000.     Dlp_CheckError(result);
  1001.     
  1002.     return Py_BuildValue("i", records);
  1003. }
  1004.  
  1005. static PyObject *
  1006. RecordIDs(self, args)
  1007.     DlpDBObject *self;
  1008.     PyObject *args;
  1009. {
  1010.     int sort=0, result;
  1011.     PyObject *list;
  1012.     int count, start;
  1013.     int i;
  1014.     recordid_t *id = (recordid_t*)self->socket->buffer;
  1015.     
  1016.     if (!PyArg_ParseTuple(args, "|i"), sort)
  1017.         return NULL;
  1018.  
  1019.     list = PyList_New(0);
  1020.     
  1021.     start = 0;
  1022.     for (;;) {
  1023.       result = dlp_ReadRecordIDList(self->socket->socket, self->handle, 
  1024.                  sort, start, 0xFFFF/sizeof(recordid_t), id, &count);
  1025.       if (result<0) {
  1026.         Py_DECREF(list);
  1027.         Dlp_CheckError(result);
  1028.       } else {
  1029.         for(i=0;i<count;i++)
  1030.            PyList_Append(list, PyInt_FromLong((long)id[i]));
  1031.         if (count == (0xFFFF/sizeof(recordid_t)))
  1032.           start = count;
  1033.         else
  1034.           break;
  1035.       }
  1036.     }
  1037.     
  1038.     return list;
  1039. }
  1040.  
  1041. static PyObject *
  1042. BlankAppBlock(self, args)
  1043.     DlpDBObject *self;
  1044.     PyObject *args;
  1045. {
  1046.     PyObject *ret;
  1047.     PyObject *c, *callargs;
  1048.     if (!PyArg_ParseTuple(args, ""))
  1049.         return NULL;
  1050.     
  1051.     c = PyObject_GetAttrString(self->Class, "AppBlock");
  1052.     callargs = Py_BuildValue("()");
  1053.     ret = PyEval_CallObject(c, callargs);
  1054.     Py_DECREF(callargs);
  1055.     return ret;
  1056. }
  1057.  
  1058. static PyObject *
  1059. BlankSortBlock(self, args)
  1060.     DlpDBObject *self;
  1061.     PyObject *args;
  1062. {
  1063.     PyObject *ret;
  1064.     PyObject *c, *callargs;
  1065.     if (!PyArg_ParseTuple(args, ""))
  1066.         return NULL;
  1067.     
  1068.     c = PyObject_GetAttrString(self->Class, "SortBlock");
  1069.     callargs = Py_BuildValue("()");
  1070.     ret = PyEval_CallObject(c, callargs);
  1071.     Py_DECREF(callargs);
  1072.     return ret;
  1073. }
  1074.  
  1075. static PyObject *
  1076. BlankRecord(self, args)
  1077.     DlpDBObject *self;
  1078.     PyObject *args;
  1079. {
  1080.     PyObject *ret;
  1081.     PyObject *c, *callargs;
  1082.     if (!PyArg_ParseTuple(args, ""))
  1083.         return NULL;
  1084.     
  1085.     c = PyObject_GetAttrString(self->Class, "Record");
  1086.     callargs = Py_BuildValue("()");
  1087.     ret = PyEval_CallObject(c, callargs);
  1088.     Py_DECREF(callargs);
  1089.     return ret;
  1090. }
  1091.  
  1092. static PyObject *
  1093. BlankResource(self, args)
  1094.     DlpDBObject *self;
  1095.     PyObject *args;
  1096. {
  1097.     PyObject *ret;
  1098.     PyObject *c, *callargs;
  1099.     if (!PyArg_ParseTuple(args, ""))
  1100.         return NULL;
  1101.     
  1102.     c = PyObject_GetAttrString(self->Class, "Resource");
  1103.     callargs = Py_BuildValue("()");
  1104.     ret = PyEval_CallObject(c, callargs);
  1105.     Py_DECREF(callargs);
  1106.     return ret;
  1107. }
  1108.  
  1109.  
  1110. static PyObject *
  1111. GetAppBlock(self, args)
  1112.     DlpDBObject *self;
  1113.     PyObject *args;
  1114. {
  1115.     int records;
  1116.     int length=0xffff,offset=0, result;
  1117.     PyObject *ret;
  1118.     PyObject *c, *callargs;
  1119.     if (!PyArg_ParseTuple(args, "|ii", &length, &offset))
  1120.         return NULL;
  1121.     
  1122.     result = dlp_ReadAppBlock(self->socket->socket, self->handle, offset, self->socket->buffer, length);
  1123.     
  1124.     Dlp_CheckError(result);
  1125.     
  1126.     c = PyObject_GetAttrString(self->Class, "AppBlock");
  1127.     callargs = Py_BuildValue("(s#O)", self->socket->buffer, result, self);
  1128.     ret = PyEval_CallObject(c, callargs);
  1129.     Py_DECREF(callargs);
  1130.     return ret;
  1131. }
  1132.  
  1133. static PyObject *
  1134. SetAppBlock(self, args)
  1135.     DlpDBObject *self;
  1136.     PyObject *args;
  1137. {
  1138.     char * data;
  1139.     int length,result;
  1140.     PyObject * h, *i, *c;
  1141.     if (!PyArg_ParseTuple(args, "O", &h))
  1142.         return NULL;
  1143.         
  1144.     h = PyObject_CallMethod(h, "pack", "O", self);
  1145.     data = PyString_AsString(h);
  1146.     length = PyString_Size(h);
  1147.  
  1148.     fprintf(stderr, "App block to write:\n");
  1149.     dumpdata(data,length);
  1150.     result = dlp_WriteAppBlock(self->socket->socket, self->handle, data, length);
  1151.     
  1152.     Dlp_CheckError(result);
  1153.     
  1154.     return Py_BuildValue("i", result);
  1155. }
  1156.  
  1157. static PyObject *
  1158. GetSortBlock(self, args)
  1159.     DlpDBObject *self;
  1160.     PyObject *args;
  1161. {
  1162.     int records;
  1163.     int length=0xffff,offset=0, result;
  1164.     PyObject *ret, *c, *callargs;
  1165.     if (!PyArg_ParseTuple(args, "|ii", &length, &offset))
  1166.         return NULL;
  1167.     
  1168.     result = dlp_ReadSortBlock(self->socket->socket, self->handle, offset, self->socket->buffer, length);
  1169.     
  1170.     Dlp_CheckError(result);
  1171.     
  1172.     c = PyObject_GetAttrString(self->Class, "SortBlock");
  1173.     callargs = Py_BuildValue("(s#O)", self->socket->buffer, result, self);
  1174.     ret = PyEval_CallObject(c, callargs);
  1175.     Py_DECREF(callargs);
  1176.     return ret;
  1177. }
  1178.  
  1179. static PyObject *
  1180. SetSortBlock(self, args)
  1181.     DlpDBObject *self;
  1182.     PyObject *args;
  1183. {
  1184.     char * data;
  1185.     int length, result;
  1186.     PyObject *h, *i;
  1187.     if (!PyArg_ParseTuple(args, "O", &h))
  1188.         return NULL;
  1189.         
  1190.     i = PyObject_CallMethod(h, "pack", "O", self);
  1191.     data = PyString_AsString(i);
  1192.     length = PyString_Size(i);
  1193.  
  1194.     result = dlp_WriteSortBlock(self->socket->socket, self->handle, data, length);
  1195.     
  1196.     Dlp_CheckError(result);
  1197.     
  1198.     return Py_BuildValue("i", result);
  1199. }
  1200.  
  1201. static PyObject *
  1202. MoveCategory(self, args)
  1203.     DlpDBObject *self;
  1204.     PyObject *args;
  1205. {
  1206.     int from,to, result;
  1207.     if (!PyArg_ParseTuple(args, "ii", &from, &to))
  1208.         return NULL;
  1209.     
  1210.     result = dlp_MoveCategory(self->socket->socket, self->handle, from, to);
  1211.  
  1212.     Dlp_CheckError(result);
  1213.     
  1214.     return Py_BuildValue("i", result);
  1215. }
  1216.  
  1217. static PyObject *
  1218. DeleteCategory(self, args)
  1219.     DlpDBObject *self;
  1220.     PyObject *args;
  1221. {
  1222.     int category, result;
  1223.     if (!PyArg_ParseTuple(args, "i", &category))
  1224.         return NULL;
  1225.     
  1226.     result = dlp_DeleteCategory(self->socket->socket, self->handle, category);
  1227.  
  1228.     Dlp_CheckError(result);
  1229.     
  1230.     return Py_BuildValue("i", result);
  1231. }
  1232.  
  1233. static PyObject *
  1234. Purge(self, args)
  1235.     DlpDBObject *self;
  1236.     PyObject *args;
  1237. {
  1238.     int result;
  1239.     if (!PyArg_ParseTuple(args, ""))
  1240.         return NULL;
  1241.     
  1242.     result = dlp_CleanUpDatabase(self->socket->socket, self->handle);
  1243.     
  1244.     Dlp_CheckError(result);
  1245.     
  1246.     return Py_BuildValue("i", result);
  1247. }
  1248.  
  1249. static PyObject *
  1250. ResetNext(self, args)
  1251.     DlpDBObject *self;
  1252.     PyObject *args;
  1253. {
  1254.     int result;
  1255.     if (!PyArg_ParseTuple(args, ""))
  1256.         return NULL;
  1257.     
  1258.     result = dlp_ResetDBIndex(self->socket->socket, self->handle);
  1259.     
  1260.     Dlp_CheckError(result);
  1261.     
  1262.     return Py_BuildValue("i", result);
  1263. }
  1264.  
  1265. static PyObject *
  1266. ResetFlags(self, args)
  1267.     DlpDBObject *self;
  1268.     PyObject *args;
  1269. {
  1270.     int result;
  1271.     if (!PyArg_ParseTuple(args, ""))
  1272.         return NULL;
  1273.         
  1274.     result = dlp_ResetSyncFlags(self->socket->socket, self->handle);
  1275.  
  1276.     Dlp_CheckError(result);
  1277.     
  1278.     return Py_BuildValue("i", result);
  1279. }
  1280.  
  1281. static PyObject *
  1282. Close(self, args)
  1283.     DlpObject *self;
  1284.     PyObject *args;
  1285. {
  1286.     int status = 0;
  1287.     int result;
  1288.     if (!PyArg_ParseTuple(args, "|i", &status))
  1289.         return NULL;
  1290.     
  1291.     if (self->socket) {
  1292.         if (status) {
  1293.             result = dlp_EndOfSync(self->socket, status);
  1294.             Dlp_CheckError(result);
  1295.         }
  1296.         result = pi_close(self->socket);
  1297.         self->socket = 0;
  1298.         if (result == -1) {
  1299.             PyErr_SetFromErrno(Error);
  1300.             return NULL;
  1301.         }
  1302.     }
  1303.     
  1304.     Py_INCREF(Py_None);
  1305.     return Py_None;
  1306. }
  1307.  
  1308. static PyObject *
  1309. Abort(self, args)
  1310.     DlpObject *self;
  1311.     PyObject *args;
  1312. {
  1313.     int result;
  1314.     if (!PyArg_ParseTuple(args, ""))
  1315.         return NULL;
  1316.     
  1317.     if (self->socket) {
  1318.         result = dlp_AbortSync(self->socket);
  1319.         Dlp_CheckError(result);
  1320.         result = pi_close(self->socket);
  1321.         self->socket = 0;
  1322.         if (result == -1) {
  1323.             PyErr_SetFromErrno(Error);
  1324.             return NULL;
  1325.         }
  1326.     }
  1327.  
  1328.     return Py_BuildValue("");
  1329. }
  1330.  
  1331. static PyObject *
  1332. GetAppPref(self, args)
  1333.     DlpObject *self;
  1334.     PyObject *args;
  1335. {
  1336.     unsigned long creator;
  1337.     int id, backup=1;
  1338.     int length, version, result;
  1339.     PyObject * ret, *p1, *p2, *f, *callargs;
  1340.     
  1341.     if (!PyArg_ParseTuple(args, "O&i|i", &ParseChar4, &creator, &id, &backup))
  1342.         return NULL;
  1343.     
  1344.     result = dlp_ReadAppPreference(self->socket, creator, id, backup,
  1345.         0xffff, self->buffer, &length, &version);
  1346.     
  1347.     Dlp_CheckError(result);
  1348.     
  1349.     if (p1 = PyDict_GetItem(PrefClasses, PyTuple_GetItem(args, 0))) {
  1350.         if (p2 = PyDict_GetItem(p1, PyTuple_GetItem(args, 1))) 
  1351.             f = p2;
  1352.         else
  1353.             if (p2 = PyDict_GetItemString(p1, ""))
  1354.                 f = p2;
  1355.     } else if (p1 = PyDict_GetItemString(PrefClasses, ""))
  1356.             f = p1;
  1357.  
  1358.     if (!f) {
  1359.         PyErr_SetString(PyExc_ValueError, "pdapilot.PrefClasses does not contain a default");
  1360.         return NULL;
  1361.     }
  1362.  
  1363.     callargs = Py_BuildValue("(s#OO&iii)", self->buffer, length, self, &BuildChar4, (void*)&creator, id, version, backup, 0, 0);
  1364.     ret = PyEval_CallObject(f, callargs);
  1365.     Py_DECREF(callargs);
  1366.     return ret;
  1367. }
  1368.  
  1369. static PyObject *
  1370. GetAppPrefRaw(self, args)
  1371.     DlpObject *self;
  1372.     PyObject *args;
  1373. {
  1374.     unsigned long creator;
  1375.     int id, backup=1;
  1376.     int length, version, result;
  1377.     PyObject * ret, *p1, *p2, *f, *callargs;
  1378.     
  1379.     if (!PyArg_ParseTuple(args, "O&i|i", &ParseChar4, &creator, &id, &backup))
  1380.         return NULL;
  1381.     
  1382.     result = dlp_ReadAppPreference(self->socket, creator, id, backup,
  1383.         0xffff, self->buffer, &length, &version);
  1384.     
  1385.     Dlp_CheckError(result);
  1386.     
  1387.     return Py_BuildValue("s#O&iii", self->buffer, length,  &BuildChar4, (void*)&creator, id, version, backup);
  1388. }
  1389.  
  1390. static PyObject *
  1391. BlankAppPref(self, args)
  1392.     DlpObject *self;
  1393.     PyObject *args;
  1394. {
  1395.     unsigned long creator;
  1396.     int id;
  1397.     int length, version, result;
  1398.     PyObject * ret, *p1, *p2, *f, *callargs;
  1399.     
  1400.     if (!PyArg_ParseTuple(args, "O&i|i", &ParseChar4, &creator, &id))
  1401.         return NULL;
  1402.     
  1403.     if (p1 = PyDict_GetItem(PrefClasses, PyTuple_GetItem(args, 0))) {
  1404.         if (p2 = PyDict_GetItem(p1, PyTuple_GetItem(args, 1))) 
  1405.             f = p2;
  1406.         else
  1407.             if (p2 = PyDict_GetItemString(p1, ""))
  1408.                 f = p2;
  1409.     } else if (p1 = PyDict_GetItemString(PrefClasses, ""))
  1410.             f = p1;
  1411.  
  1412.     if (!f) {
  1413.         PyErr_SetString(PyExc_ValueError, "pdapilot.PrefClasses does not contain a default");
  1414.         return NULL;
  1415.     }
  1416.  
  1417.     Py_INCREF(Py_None);
  1418.     callargs = Py_BuildValue("(OOO&i)", Py_None, self, &BuildChar4, (void*)&creator, id);
  1419.     ret = PyEval_CallObject(f, callargs);
  1420.     Py_DECREF(callargs);
  1421.     return ret;
  1422. }
  1423.  
  1424.  
  1425. static PyObject *
  1426. SetAppPref(self, args)
  1427.     DlpObject *self;
  1428.     PyObject *args;
  1429. {
  1430.     unsigned long creator;
  1431.     int id=0, length, version=0, backup=1, result;
  1432.     char * data;
  1433.     PyObject *h, *i;
  1434.  
  1435.     if (!PyArg_ParseTuple(args, "O", &h))
  1436.         return NULL;
  1437.         
  1438.     i = PyObject_CallMethod(h, "pack", "O", self);
  1439.     data = PyString_AsString(i);
  1440.     length = PyString_Size(i);
  1441.  
  1442.     if (!(i=PyObject_GetAttrString(h, "creator")) || (i == Py_None)) 
  1443.         { PyErr_SetString(PyExc_ValueError, "The pref's .creator attribute must be set");
  1444.             return NULL; } 
  1445.     else
  1446.         creator = ParseChar4(i);
  1447.     if (i=PyObject_GetAttrString(h, "id")) id = PyInt_AsLong(i);
  1448.     if (i=PyObject_GetAttrString(h, "version")) version = PyInt_AsLong(i);
  1449.     if (i=PyObject_GetAttrString(h, "backup")) backup = PyInt_AsLong(i);
  1450.     
  1451.     result = dlp_WriteAppPreference(self->socket, creator, id, backup,
  1452.         version, data, length);
  1453.         
  1454.     Dlp_CheckError(result);
  1455.  
  1456.     return Py_BuildValue("i", result);
  1457. }
  1458.  
  1459. static PyObject *
  1460. SetAppPrefRaw(self, args)
  1461.     DlpObject *self;
  1462.     PyObject *args;
  1463. {
  1464.     unsigned long creator;
  1465.     int id=0, length, version=0, backup=1, result;
  1466.     char * data;
  1467.     PyObject *h, *i;
  1468.  
  1469.     if (!PyArg_ParseTuple(args, "s#O&iii", &data, &length, &ParseChar4, &creator, &id, &version, &backup))
  1470.         return NULL;
  1471.         
  1472.     result = dlp_WriteAppPreference(self->socket, creator, id, backup,
  1473.         version, data, length);
  1474.         
  1475.     Dlp_CheckError(result);
  1476.  
  1477.     return Py_BuildValue("i", result);
  1478. }
  1479.  
  1480.  
  1481. static PyObject *
  1482. DBGetAppPref(self, args)
  1483.     DlpDBObject *self;
  1484.     PyObject *args;
  1485. {
  1486.     unsigned long creator;
  1487.     int id=0, backup=1;
  1488.     int length, version, result;
  1489.     int r;
  1490.     PyObject * ret, *p1, *p2, *f, *callargs;
  1491.     
  1492.     if (!PyArg_ParseTuple(args, "|ii", &id, &backup))
  1493.         return NULL;
  1494.     
  1495.     f = PyObject_GetAttrString(self->Class, "creator");
  1496.     if (!f) {
  1497.         PyErr_SetString(Error, "unable to retrieve creator from db class");
  1498.         return NULL;
  1499.     }
  1500.     if (!ParseChar4(f, &creator))
  1501.         return NULL;
  1502.     
  1503.     if (pi_version(self->socket->socket)<0x101)
  1504.         r = dlp_CloseDB(self->socket->socket, self->handle);
  1505.     
  1506.     result = dlp_ReadAppPreference(self->socket->socket, creator, id, backup,
  1507.         0xffff, self->socket->buffer, &length, &version);
  1508.  
  1509.     if (pi_version(self->socket->socket)<0x101)
  1510.         r = dlp_OpenDB(self->socket->socket, self->dbcard, self->dbmode, PyString_AsString(self->dbname), &self->handle);
  1511.     
  1512.     Dlp_CheckError(result);
  1513.     
  1514.     f = PyObject_GetAttrString(self->Class, "Pref");
  1515.     callargs = Py_BuildValue("(s#OO&iii)", self->socket->buffer, length, self, &BuildChar4, (void*)&creator, id, version, backup, 0, 0);
  1516.     ret = PyEval_CallObject(f, callargs);
  1517.     Py_DECREF(callargs);
  1518.     return ret;
  1519. }
  1520.  
  1521. static PyObject *
  1522. DBBlankAppPref(self, args)
  1523.     DlpDBObject *self;
  1524.     PyObject *args;
  1525. {
  1526.     unsigned long creator;
  1527.     int id=0;
  1528.     int length, version, result, backup=0;
  1529.     PyObject * ret, *p1, *p2, *f, *callargs;
  1530.     
  1531.     if (!PyArg_ParseTuple(args, "|ii", &id, &backup))
  1532.         return NULL;
  1533.  
  1534.     p1 = PyObject_GetAttrString(self->Class, "creator");
  1535.     if (!p1) {
  1536.         PyErr_SetString(Error, "unable to retrieve creator from db class");
  1537.         return NULL;
  1538.     }
  1539.     if (!ParseChar4(p1, &creator))
  1540.         return NULL;
  1541.  
  1542.     p2 = PyObject_GetAttrString(self->Class, "Pref");
  1543.     
  1544.     Py_INCREF(Py_None);
  1545.     callargs = Py_BuildValue("(OOO&i)", Py_None, self, &BuildChar4, (void*)&creator, id);
  1546.     ret = PyEval_CallObject(p2, callargs);
  1547.     Py_DECREF(callargs);
  1548.     return ret;
  1549. }
  1550.  
  1551.  
  1552. static PyObject *
  1553. DBSetAppPref(self, args)
  1554.     DlpDBObject *self;
  1555.     PyObject *args;
  1556. {
  1557.     unsigned long creator;
  1558.     int id=0, length, version=0, backup=1, result;
  1559.     char * data;
  1560.     int r;
  1561.     PyObject *h, *i;
  1562.  
  1563.     if (!PyArg_ParseTuple(args, "O", &h))
  1564.         return NULL;
  1565.         
  1566.     i = PyObject_CallMethod(h, "pack", "O", self);
  1567.     data = PyString_AsString(i);
  1568.     length = PyString_Size(i);
  1569.  
  1570.     if (!(i=PyObject_GetAttrString(h, "creator")) || (i == Py_None)) 
  1571.         { PyErr_SetString(PyExc_ValueError, "The pref's .creator attribute must be set");
  1572.             return NULL; } 
  1573.     else
  1574.         creator = ParseChar4(i);
  1575.     if (i=PyObject_GetAttrString(h, "id")) id = PyInt_AsLong(i);
  1576.     if (i=PyObject_GetAttrString(h, "version")) version = PyInt_AsLong(i);
  1577.     if (i=PyObject_GetAttrString(h, "backup")) backup = PyInt_AsLong(i);
  1578.     
  1579.     if (pi_version(self->socket->socket)<0x101)
  1580.         r = dlp_CloseDB(self->socket->socket, self->handle);
  1581.  
  1582.     result = dlp_WriteAppPreference(self->socket->socket, creator, id, backup,
  1583.         version, data, length);
  1584.  
  1585.     if (pi_version(self->socket->socket)<0x101)
  1586.         r = dlp_OpenDB(self->socket->socket, self->dbcard, self->dbmode, PyString_AsString(self->dbname), &self->handle);
  1587.         
  1588.     Dlp_CheckError(result);
  1589.  
  1590.     return Py_BuildValue("i", result);
  1591. }
  1592.  
  1593. static PyObject *
  1594. DeleteDB(self, args)
  1595.     DlpObject *self;
  1596.     PyObject *args;
  1597. {
  1598.     char * name;
  1599.     int cardno = 0;
  1600.     int result;
  1601.     if (!PyArg_ParseTuple(args, "s|i", &name, &cardno))
  1602.         return NULL;
  1603.  
  1604.     result = dlp_DeleteDB(self->socket, cardno, name);
  1605.     
  1606.     Dlp_CheckError(result);
  1607.  
  1608.     return Py_BuildValue("i", result);
  1609. }
  1610.  
  1611. static PyObject *
  1612. Status(self, args)
  1613.     DlpObject *self;
  1614.     PyObject *args;
  1615. {
  1616.     int result;
  1617.     if (!PyArg_ParseTuple(args, ""))
  1618.         return NULL;
  1619.     
  1620.     result = dlp_OpenConduit(self->socket);
  1621.     
  1622.     Dlp_CheckError(result);
  1623.  
  1624.     return Py_BuildValue("i", result);
  1625. }
  1626.  
  1627. static PyObject *
  1628. Battery(self, args)
  1629.     DlpObject *self;
  1630.     PyObject *args;
  1631. {
  1632.     int warn, critical, ticks, kind, AC;
  1633.     unsigned long voltage;
  1634.     int result;
  1635.     struct RPC_params p;
  1636.     if (!PyArg_ParseTuple(args, ""))
  1637.         return NULL;
  1638.  
  1639.     PackRPC(&p,0xA0B6, RPC_IntReply,
  1640.         RPC_Byte(0), RPC_ShortPtr(&warn), RPC_ShortPtr(&critical),
  1641.         RPC_ShortPtr(&ticks), RPC_BytePtr(&kind), RPC_BytePtr(&AC), RPC_End);
  1642.     
  1643.     result = dlp_RPC(self->socket, &p, &voltage);
  1644.     
  1645.     return Py_BuildValue("(fffii)", (float)voltage/100, 
  1646.         (float)warn/100, (float)critical/100, kind, AC);
  1647. }
  1648.  
  1649. static PyObject *
  1650. GetTime(self, args)
  1651.     DlpObject *self;
  1652.     PyObject *args;
  1653. {
  1654.     unsigned long time;
  1655.     int result;
  1656.     if (!PyArg_ParseTuple(args, ""))
  1657.         return NULL;
  1658.         
  1659.     result = dlp_GetSysDateTime(self->socket, &time);
  1660.     
  1661.     Dlp_CheckError(result);
  1662.  
  1663.     return Py_BuildValue("l", (long)time);
  1664. }
  1665.  
  1666. static PyObject *
  1667. GetFeature(self, args)
  1668.     DlpObject *self;
  1669.     PyObject *args;
  1670. {
  1671.     unsigned long creator, feature;
  1672.     int result, number;
  1673.     if (!PyArg_ParseTuple(args, "O&i"), &ParseChar4, &creator, &number)
  1674.         return NULL;
  1675.         
  1676.     result = dlp_ReadFeature(self->socket, creator, number, &feature);
  1677.     
  1678.     Dlp_CheckError(result);
  1679.  
  1680.     return Py_BuildValue("l", (long)feature);
  1681. }
  1682.  
  1683. static PyObject *
  1684. CallApp(self, args)
  1685.     DlpObject *self;
  1686.     PyObject *args;
  1687. {
  1688.     unsigned long creator, type;
  1689.     int action, length = 0;
  1690.     char * data = 0;
  1691.     int result;
  1692.     unsigned long retcode;
  1693.     int maxlength=0xffff;
  1694.     if (!PyArg_ParseTuple(args, "O&O&i|s#l", &ParseChar4, &creator, &ParseChar4, &type, &action, &data, &length, &maxlength))
  1695.         return NULL;
  1696.     
  1697.     result = dlp_CallApplication(self->socket, creator, type, action, 
  1698.         length, data, &retcode, maxlength, &length, self->buffer);
  1699.     
  1700.     Dlp_CheckError(result);
  1701.     
  1702.     return Py_BuildValue("ls#", (long)retcode, self->buffer, length);
  1703. }
  1704.  
  1705. static PyObject *
  1706. Log(self, args)
  1707.     DlpObject *self;
  1708.     PyObject *args;
  1709. {
  1710.     char * string;
  1711.     int result;
  1712.     if (!PyArg_ParseTuple(args, "s", &string))
  1713.         return NULL;
  1714.     
  1715.     result = dlp_AddSyncLogEntry(self->socket, string);
  1716.  
  1717.     Dlp_CheckError(result);
  1718.  
  1719.     return Py_BuildValue("i", result);
  1720. }
  1721.  
  1722. static PyObject *
  1723. CardInfo(self, args)
  1724.     DlpObject *self;
  1725.     PyObject *args;
  1726. {
  1727.     int cardno=0;
  1728.     int result;
  1729.     struct CardInfo s;
  1730.     if (!PyArg_ParseTuple(args, "|i", &cardno))
  1731.         return NULL;
  1732.  
  1733.     result = dlp_ReadStorageInfo(self->socket, cardno, &s);
  1734.     
  1735.     Dlp_CheckError(result);
  1736.     
  1737.     return Py_BuildValue("{sisislslslslssss}",
  1738.         "card", s.card,
  1739.         "version", s.version,
  1740.         "created", (long)s.creation,
  1741.         "romSize", (long)s.romSize,
  1742.         "ramSize", (long)s.ramSize,
  1743.         "ramFree", (long)s.ramFree,
  1744.         "name", s.name,
  1745.         "manufacturer", s.manufacturer);
  1746. }
  1747.  
  1748. static PyObject *
  1749. GetUserInfo(self, args)
  1750.     DlpObject *self;
  1751.     PyObject *args;
  1752. {
  1753.     int result;
  1754.     struct PilotUser p;
  1755.     if (!PyArg_ParseTuple(args, ""))
  1756.         return NULL;
  1757.  
  1758.     result = dlp_ReadUserInfo(self->socket, &p);
  1759.     
  1760.     Dlp_CheckError(result);
  1761.     
  1762.     return Py_BuildValue("{slslssslslslss#}",
  1763.         "userID", (long)p.userID,
  1764.         "viewerID", (long)p.viewerID,
  1765.         "name", p.username,
  1766.         "lastSyncPC", (long)p.lastSyncPC,
  1767.         "successfulSyncDate", (long)p.successfulSyncDate,
  1768.         "lastSyncDate", (long)p.lastSyncDate,
  1769.         "password", p.password, p.passwordLength
  1770.         );
  1771. }
  1772.  
  1773.  
  1774. static PyObject *
  1775. BuildDBInfo(i)
  1776.     struct DBInfo * i;
  1777. {
  1778.     return Py_BuildValue("{sisisisisisisisisisOsOsisislslslslss}",
  1779.         "more", i->more,
  1780.         "flagResource", !!(i->flags & dlpDBFlagResource),
  1781.         "flagReadOnly", !!(i->flags & dlpDBFlagReadOnly),
  1782.         "flagAppInfoDirty", !!(i->flags & dlpDBFlagAppInfoDirty),
  1783.         "flagBackup", !!(i->flags & dlpDBFlagBackup),
  1784.         "flagOpen", !!(i->flags & dlpDBFlagOpen),
  1785.         "flagNewer", !!(i->flags & dlpDBFlagNewer),
  1786.         "flagReset", !!(i->flags & dlpDBFlagReset),
  1787.         "flagExcludeFromSync", !!(i->miscFlags & dlpDBMiscFlagExcludeFromSync),
  1788.         "type", BuildChar4(&i->type),
  1789.         "creator", BuildChar4(&i->creator),
  1790.         "version", i->version,
  1791.         "index", i->index,
  1792.         "modnum", (long)i->modnum,
  1793.         "createDate", (long)i->createDate,
  1794.         "modifyDate", (long)i->modifyDate,
  1795.         "backupDate", (long)i->backupDate,
  1796.         "name", i->name
  1797.         );
  1798. }
  1799.  
  1800. static int ParseDBInfo(d, i)
  1801.     PyObject * d;
  1802.     struct DBInfo * i;
  1803. {
  1804.     PyObject * e;
  1805.     
  1806.     memset(i, '\0', sizeof(struct DBInfo));
  1807.     
  1808.     i->flags = 0
  1809.         | (((e=PyDict_GetItemString(d, "flagResource")) && PyInt_AsLong(e)) ? dlpDBFlagResource : 0)
  1810.         | (((e=PyDict_GetItemString(d, "flagReadOnly")) && PyInt_AsLong(e)) ? dlpDBFlagReadOnly : 0)
  1811.         | (((e=PyDict_GetItemString(d, "flagAppInfoDirty")) && PyInt_AsLong(e)) ? dlpDBFlagAppInfoDirty : 0)
  1812.         | (((e=PyDict_GetItemString(d, "flagBackup")) && PyInt_AsLong(e)) ? dlpDBFlagBackup : 0)
  1813.         | (((e=PyDict_GetItemString(d, "flagOpen")) && PyInt_AsLong(e)) ? dlpDBFlagOpen : 0)
  1814.         | (((e=PyDict_GetItemString(d, "flagNewer")) && PyInt_AsLong(e)) ? dlpDBFlagNewer : 0)
  1815.         | (((e=PyDict_GetItemString(d, "flagReset")) && PyInt_AsLong(e)) ? dlpDBFlagReset : 0)
  1816.     ;
  1817.     
  1818.     i->miscFlags = 0
  1819.         | (((e=PyDict_GetItemString(d, "flagExcludeFromSync")) && PyInt_AsLong(e)) ? dlpDBMiscFlagExcludeFromSync : 0)
  1820.     ;
  1821.     e=PyDict_GetItemString(d, "type");
  1822.     if (e) {
  1823.         if (ParseChar4(e, &i->type)==0)
  1824.             return 0;
  1825.     } else
  1826.         i->type = 0;
  1827.     e=PyDict_GetItemString(d, "creator");
  1828.     if (e) {
  1829.         if (ParseChar4(e, &i->creator)==0)
  1830.             return 0;
  1831.     } else
  1832.         i->creator = 0;
  1833.     i->more = (e=PyDict_GetItemString(d, "more")) ? PyInt_AsLong(e) : 0;
  1834.     i->version = (e=PyDict_GetItemString(d, "version")) ? PyInt_AsLong(e) : 0;
  1835.     i->modnum = (e=PyDict_GetItemString(d, "modnum")) ? PyInt_AsLong(e) : 0;
  1836.     i->index = (e=PyDict_GetItemString(d, "index")) ? PyInt_AsLong(e) : 0;
  1837.     i->createDate = (e=PyDict_GetItemString(d, "createDate")) ? PyInt_AsLong(e) : 0;
  1838.     i->modifyDate = (e=PyDict_GetItemString(d, "modifyDate")) ? PyInt_AsLong(e) : 0;
  1839.     i->backupDate = (e=PyDict_GetItemString(d, "backupDate")) ? PyInt_AsLong(e) : 0;
  1840.     strcpy(i->name, (e=PyDict_GetItemString(d, "name")) ? PyString_AsString(e) : "");
  1841.     
  1842.     return 1;
  1843. }
  1844.     
  1845.  
  1846. static PyObject *
  1847. SetUserInfo(self, args)
  1848.     DlpObject *self;
  1849.     PyObject *args;
  1850. {
  1851.     int result;
  1852.     PyObject * d, *e;
  1853.     struct PilotUser p;
  1854.     if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &d))
  1855.         return NULL;
  1856.     
  1857.     if (!PyDict_Check(d))
  1858.         return NULL;
  1859.         
  1860.     memset(&p, '\0', sizeof(struct PilotUser));
  1861.     
  1862.     p.userID = (e=PyDict_GetItemString(d, "userID")) ? PyInt_AsLong(e) : 0;
  1863.     p.viewerID = (e=PyDict_GetItemString(d, "viewerID")) ? PyInt_AsLong(e) : 0;
  1864.     p.lastSyncPC = (e=PyDict_GetItemString(d, "lastSyncPC")) ? PyInt_AsLong(e) : 0;
  1865.     p.successfulSyncDate = (e=PyDict_GetItemString(d, "successfulSyncDate")) ? PyInt_AsLong(e) : 0;
  1866.     p.lastSyncDate = (e=PyDict_GetItemString(d, "lastSyncDate")) ? PyInt_AsLong(e) : 0;
  1867.     strcpy(p.username, (e=PyDict_GetItemString(d, "name")) ? PyString_AsString(e) : "");
  1868.  
  1869.     result = dlp_WriteUserInfo(self->socket, &p);
  1870.     
  1871.     Dlp_CheckError(result);
  1872.     
  1873.     return Py_BuildValue(""); /* None */
  1874. }
  1875.  
  1876. static PyObject *
  1877. SysInfo(self, args)
  1878.     DlpObject *self;
  1879.     PyObject *args;
  1880. {
  1881.     int result;
  1882.     struct SysInfo s;
  1883.     if (!PyArg_ParseTuple(args, ""))
  1884.         return NULL;
  1885.  
  1886.     result = dlp_ReadSysInfo(self->socket, &s);
  1887.     
  1888.     Dlp_CheckError(result);
  1889.     
  1890.     return Py_BuildValue("{slslss}",
  1891.         "romVersion", (long)s.romVersion,
  1892.         "locale", (long)s.locale,
  1893.         "name", s.name);
  1894. }
  1895.  
  1896. static PyObject *
  1897. GetDBInfo(self, args)
  1898.     DlpObject *self;
  1899.     PyObject *args;
  1900. {
  1901.     int result;
  1902.     int db, where, RAM=1, ROM=0, cardno=0;
  1903.     struct DBInfo i;
  1904.     
  1905.     if (!PyArg_ParseTuple(args, "i|iii", &db, &RAM, &ROM, &cardno))
  1906.         return NULL;
  1907.     
  1908.     where = (RAM ? dlpDBListRAM : 0) | (ROM ? dlpDBListROM : 0);
  1909.  
  1910.     result = dlp_ReadDBList(self->socket, cardno, where, db, &i);
  1911.     
  1912.     if (result == -5) {
  1913.         return Py_BuildValue(""); 
  1914.     }
  1915.     
  1916.     Dlp_CheckError(result);
  1917.     
  1918.     return BuildDBInfo(&i);
  1919. }
  1920.  
  1921. static PyObject *
  1922. FindDBInfo(self, args)
  1923.     DlpObject *self;
  1924.     PyObject *args;
  1925. {
  1926.     int result;
  1927.     int db, cardno=0;
  1928.     char * name;
  1929.     PyObject *creator, *type;
  1930.     unsigned long cl, tl;
  1931.     struct DBInfo i;
  1932.     
  1933.     if (!PyArg_ParseTuple(args, "izOO|i", &db, &name, &creator, &type, &cardno))
  1934.         return NULL;
  1935.  
  1936.     if (creator == Py_None)
  1937.         cl = 0;
  1938.     else
  1939.         if (ParseChar4(creator, &cl) == 0)
  1940.             return NULL;
  1941.  
  1942.     if (type == Py_None)
  1943.         tl = 0;
  1944.     else
  1945.         if (ParseChar4(type, &tl) == 0)
  1946.             return NULL;
  1947.  
  1948.     result = dlp_FindDBInfo(self->socket, cardno, db, name, tl, cl, &i);
  1949.     
  1950.     Dlp_CheckError(result);
  1951.     
  1952.     return BuildDBInfo(&i);
  1953. }
  1954.  
  1955. static PyObject *
  1956. SetTime(self, args)
  1957.     DlpObject *self;
  1958.     PyObject *args;
  1959. {
  1960.     unsigned long time;
  1961.     int result;
  1962.     if (!PyArg_ParseTuple(args, "l", &time))
  1963.         return NULL;
  1964.     
  1965.     result = dlp_SetSysDateTime(self->socket, time);
  1966.     
  1967.     Dlp_CheckError(result);
  1968.  
  1969.     return Py_BuildValue("l", (long)time);
  1970. }
  1971.  
  1972. static PyObject *
  1973. OpenFile(self, args)
  1974.     PyObject *self;
  1975.     PyObject *args;
  1976. {
  1977.     char * name;
  1978.     struct pi_file * pf;
  1979.     PiFileObject * retval;
  1980.     PyObject * packer;
  1981.     if (!PyArg_ParseTuple(args, "s", &name))
  1982.         return NULL;
  1983.  
  1984.     pf = pi_file_open(name);
  1985.     if (!pf) {
  1986.         PyErr_SetString(Error, "Unable to open file");
  1987.         return NULL;
  1988.     }
  1989.     
  1990.     retval = PyObject_NEW(PiFileObject, &PiFile_Type);
  1991.     retval->pf = pf;
  1992.  
  1993.     retval->Class = 0;
  1994.     packer = PyDict_GetItemString(DBClasses, name);
  1995.     if (!packer)
  1996.         packer = PyDict_GetItemString(DBClasses, "");
  1997.     if (!packer) {
  1998.         PyErr_SetString(PyExc_ValueError, "pdapilot.DBClasses must contain a default");
  1999.         pi_file_close(retval->pf);
  2000.         free(retval);
  2001.         return NULL;
  2002.     }
  2003.     if (packer) {
  2004.         retval->Class = packer;
  2005.         Py_XINCREF(packer);
  2006.     }
  2007.  
  2008.     return (PyObject*)retval;
  2009. }
  2010.  
  2011.  
  2012. static PyObject *
  2013. CreateFile(self, args)
  2014.     PyObject *self;
  2015.     PyObject *args;
  2016. {
  2017.     char * name;
  2018.     struct pi_file * pf;
  2019.     struct DBInfo i;
  2020.     PiFileObject * retval;
  2021.     PyObject * d, *packer;
  2022.     if (!PyArg_ParseTuple(args, "sO!", &name, &PyDict_Type, &d))
  2023.         return NULL;
  2024.     
  2025.     if (ParseDBInfo(d, &i)==0)
  2026.         return NULL;
  2027.  
  2028.     pf = pi_file_create(name, &i);
  2029.     if (!pf) {
  2030.         PyErr_SetString(Error, "Unable to create file");
  2031.         return NULL;
  2032.     }
  2033.     
  2034.     retval = PyObject_NEW(PiFileObject, &PiFile_Type);
  2035.     retval->pf = pf;
  2036.  
  2037.     retval->Class = 0;
  2038.     packer = PyDict_GetItemString(DBClasses, name);
  2039.     if (!packer)
  2040.         packer = PyDict_GetItemString(DBClasses, "");
  2041.     if (!packer) {
  2042.         PyErr_SetString(PyExc_ValueError, "pdapilot.DBClasses must contain a default");
  2043.         pi_file_close(retval->pf);
  2044.         free(retval);
  2045.         return NULL;
  2046.     }
  2047.     if (packer) {
  2048.         retval->Class = packer;
  2049.         Py_XINCREF(packer);
  2050.     }
  2051.  
  2052.     return (PyObject*)retval;
  2053. }
  2054.  
  2055. static PyObject *
  2056. FileClose(self, args)
  2057.     PiFileObject *self;
  2058.     PyObject *args;
  2059. {
  2060.     if (!PyArg_ParseTuple(args, ""))
  2061.         return NULL;
  2062.         
  2063.     pi_file_close(self->pf);
  2064.     self->pf = 0;
  2065.  
  2066.     return Py_BuildValue("");
  2067. }
  2068.  
  2069. static PyObject *
  2070. FileRecords(self, args)
  2071.     PiFileObject *self;
  2072.     PyObject *args;
  2073. {
  2074.     int records;
  2075.     
  2076.     if (!PyArg_ParseTuple(args, ""))
  2077.         return NULL;
  2078.         
  2079.     if (pi_file_get_entries(self->pf, &records)==-1)
  2080.         return Py_BuildValue("");
  2081.     else
  2082.         return Py_BuildValue("i", records);
  2083. }
  2084.  
  2085. static PyObject *
  2086. FileCheckID(self, args)
  2087.     PiFileObject *self;
  2088.     PyObject *args;
  2089. {
  2090.     int records;
  2091.     unsigned long id;
  2092.     
  2093.     if (!PyArg_ParseTuple(args, "l", id))
  2094.         return NULL;
  2095.         
  2096.     return Py_BuildValue("i", pi_file_id_used(self->pf, id));
  2097. }
  2098.  
  2099. static PyObject *
  2100. FileGetRec(self, args)
  2101.     PiFileObject *self;
  2102.     PyObject *args;
  2103. {
  2104.     int index, attr, category;
  2105.     void * c;
  2106.     int length;
  2107.     unsigned long id;
  2108.     if (!PyArg_ParseTuple(args, "i", &index))
  2109.         return NULL;
  2110.     
  2111.     if (pi_file_read_record(self->pf, index, &c, &length, &attr, &category, &id)==-1)
  2112.         return Py_BuildValue("");
  2113.     else    {
  2114.         PyObject * cl = PyObject_GetAttrString(self->Class, "Record");
  2115.         PyObject * callargs = Py_BuildValue("(s#Oilii)", c, length, self, index, (long)id, attr, category);
  2116.         PyObject * ret = PyEval_CallObject(cl, callargs);
  2117.         Py_DECREF(callargs);
  2118.         return ret;
  2119.     }
  2120. }
  2121.  
  2122. static PyObject *
  2123. FileGetRecById(self, args)
  2124.     PiFileObject *self;
  2125.     PyObject *args;
  2126. {
  2127.     int index, attr, category;
  2128.     void * c;
  2129.     int length;
  2130.     unsigned long id;
  2131.     if (!PyArg_ParseTuple(args, "l", &id))
  2132.         return NULL;
  2133.     
  2134.     if (pi_file_read_record_by_id(self->pf, id, &c, &length, &index, &attr, &category)==-1)
  2135.         return Py_BuildValue("");
  2136.     else {
  2137.         PyObject * cl = PyObject_GetAttrString(self->Class, "Record");
  2138.         PyObject * callargs = Py_BuildValue("(s#Oilii)", c, length, self, index, (long)id, attr, category);
  2139.         PyObject * ret = PyEval_CallObject(cl, callargs);
  2140.         Py_DECREF(callargs);
  2141.         return ret;
  2142.     }
  2143. }
  2144.  
  2145. static PyObject *
  2146. FileGetDBInfo(self, args)
  2147.     PiFileObject *self;
  2148.     PyObject *args;
  2149. {
  2150.     struct DBInfo i;
  2151.     if (!PyArg_ParseTuple(args, ""))
  2152.         return NULL;
  2153.     
  2154.     if (pi_file_get_info(self->pf, &i)==-1) {
  2155.         PyErr_SetFromErrno(Error);
  2156.         return NULL;
  2157.     } else
  2158.         return BuildDBInfo(&i);
  2159. }
  2160.  
  2161. static PyObject *
  2162. FileSetDBInfo(self, args)
  2163.     PiFileObject *self;
  2164.     PyObject *args;
  2165. {
  2166.     PyObject *o;
  2167.     struct DBInfo i;
  2168.     if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &o))
  2169.         return NULL;
  2170.     
  2171.     if (ParseDBInfo(o, &i)==0)
  2172.         return NULL;
  2173.     
  2174.     if (pi_file_set_info(self->pf, &i)==-1) {
  2175.         PyErr_SetFromErrno(Error);
  2176.         return NULL;
  2177.     } else
  2178.         return Py_BuildValue("");
  2179. }
  2180.  
  2181.  
  2182.  
  2183. static PyObject *
  2184. FileGetAppBlock(self, args)
  2185.     PiFileObject *self;
  2186.     PyObject *args;
  2187. {
  2188.     void * c;
  2189.     int length;
  2190.     if (!PyArg_ParseTuple(args, ""))
  2191.         return NULL;
  2192.     
  2193.     if (pi_file_get_app_info(self->pf, &c, &length)==-1) {
  2194.         PyErr_SetFromErrno(Error);
  2195.         return NULL;
  2196.     } else    {
  2197.         PyObject *    cl = PyObject_GetAttrString(self->Class, "AppBlock");
  2198.         PyObject * callargs = Py_BuildValue("(s#O)", c, length, self);
  2199.         PyObject * ret = PyEval_CallObject(cl, callargs);
  2200.         Py_DECREF(callargs);
  2201.         return ret;
  2202.     }
  2203. }
  2204.  
  2205. static PyObject *
  2206. FileSetAppBlock(self, args)
  2207.     PiFileObject *self;
  2208.     PyObject *args;
  2209. {
  2210.     char * c;
  2211.     int length;
  2212.     PyObject *h, *i;
  2213.     if (!PyArg_ParseTuple(args, "O", &h))
  2214.         return NULL;
  2215.         
  2216.     h = PyObject_CallMethod(h, "pack", "O", self);
  2217.     c = PyString_AsString(h);
  2218.     length = PyString_Size(h);
  2219.  
  2220.     if (pi_file_set_app_info(self->pf, c, length)==-1) {
  2221.         PyErr_SetFromErrno(Error);
  2222.         return NULL;
  2223.     } else
  2224.         return Py_BuildValue("");
  2225. }
  2226.  
  2227. static PyObject *
  2228. FileGetSortBlock(self, args)
  2229.     PiFileObject *self;
  2230.     PyObject *args;
  2231. {
  2232.     void * c;
  2233.     int length;
  2234.     if (!PyArg_ParseTuple(args, ""))
  2235.         return NULL;
  2236.     
  2237.     if (pi_file_get_sort_info(self->pf, &c, &length)==-1) {
  2238.         PyErr_SetFromErrno(Error);
  2239.         return NULL;
  2240.     } else {
  2241.         PyObject *    cl = PyObject_GetAttrString(self->Class, "SortBlock");
  2242.         PyObject * callargs = Py_BuildValue("(s#O)", c, length, self);
  2243.         PyObject * ret = PyEval_CallObject(cl, callargs);
  2244.         Py_DECREF(callargs);
  2245.         return ret;
  2246.     }
  2247. }
  2248.  
  2249. static PyObject *
  2250. FileSetSortBlock(self, args)
  2251.     PiFileObject *self;
  2252.     PyObject *args;
  2253. {
  2254.     char * c;
  2255.     int length;
  2256.     PyObject *h, *i;
  2257.     if (!PyArg_ParseTuple(args, "O", &h))
  2258.         return NULL;
  2259.         
  2260.     h = PyObject_CallMethod(h, "pack", "O", self);
  2261.     c = PyString_AsString(h);
  2262.     length = PyString_Size(h);
  2263.     
  2264.     if (pi_file_set_sort_info(self->pf, c, length)==-1) {
  2265.         PyErr_SetFromErrno(Error);
  2266.         return NULL;
  2267.     } else
  2268.         return Py_BuildValue("");
  2269. }
  2270.  
  2271. static PyObject *
  2272. FileGetRsc(self, args)
  2273.     PiFileObject *self;
  2274.     PyObject *args;
  2275. {
  2276.     int index, id;
  2277.     void * c;
  2278.     int length;
  2279.     unsigned long type;
  2280.     if (!PyArg_ParseTuple(args, "i", &index))
  2281.         return NULL;
  2282.     
  2283.     if (pi_file_read_resource(self->pf, index, &c, &length, &type, &id)==-1)
  2284.         return Py_BuildValue("");
  2285.     else {
  2286.         PyObject * cl = PyObject_GetAttrString(self->Class, "Resource");
  2287.         PyObject * callargs = Py_BuildValue("(s#OO&i)", c, length, self, &BuildChar4, &type, id);
  2288.         PyObject * ret = PyEval_CallObject(cl, callargs);
  2289.         Py_DECREF(callargs);
  2290.         return ret;
  2291.     }
  2292. }
  2293.  
  2294. static PyObject *
  2295. FileAddRec(self, args)
  2296.     PiFileObject *self;
  2297.     PyObject *args;
  2298. {
  2299.     unsigned long id=0;
  2300.     unsigned long newid;
  2301.     int length, attr=0, category=0;
  2302.     char * data;
  2303.     int result;
  2304.     PyObject *h, *i;
  2305.     if (!PyArg_ParseTuple(args, "O", &h))
  2306.         return NULL;
  2307.         
  2308.     i = PyObject_CallMethod(h, "pack", "O", self);
  2309.     data = PyString_AsString(i);
  2310.     length = PyString_Size(i);
  2311.  
  2312.     if (!(i=PyObject_GetAttrString(h, "id")))
  2313.         { PyErr_SetString(PyExc_ValueError, "The record's .id attribute must be set");
  2314.             return NULL; } 
  2315.     else if (i == Py_None) 
  2316.         id = 0;
  2317.     else
  2318.         id = PyInt_AsLong(i);
  2319.     attr = 0;
  2320.     if ((i=PyObject_GetAttrString(h, "deleted")) && PyInt_AsLong(i))
  2321.         attr |= 0x80;
  2322.     if ((i=PyObject_GetAttrString(h, "modified")) && PyInt_AsLong(i))
  2323.         attr |= 0x40;
  2324.     if ((i=PyObject_GetAttrString(h, "busy")) && PyInt_AsLong(i))
  2325.         attr |= 0x20;
  2326.     if ((i=PyObject_GetAttrString(h, "secret")) && PyInt_AsLong(i))
  2327.         attr |= 0x10;
  2328.     if ((i=PyObject_GetAttrString(h, "archived")) && PyInt_AsLong(i))
  2329.         attr |= 0x08;
  2330.     /*if (i=PyObject_GetAttrString(h, "attr")) attr = PyInt_AsLong(i);*/
  2331.     if (i=PyObject_GetAttrString(h, "category")) category = PyInt_AsLong(i);
  2332.     
  2333.     if (pi_file_append_record(self->pf, data, length, attr, category, id)==-1) {
  2334.         PyErr_SetFromErrno(Error);
  2335.         return NULL;
  2336.     } 
  2337.     
  2338.     return Py_BuildValue("l", (long)id);
  2339. }
  2340.  
  2341. static PyObject *
  2342. FileAddRsc(self, args)
  2343.     PiFileObject *self;
  2344.     PyObject *args;
  2345. {
  2346.     unsigned long type;
  2347.     int id, length;
  2348.     char * data;
  2349.     int result;
  2350.     PyObject *h, *i;
  2351.     if (!PyArg_ParseTuple(args, "O", &h))
  2352.         return NULL;
  2353.         
  2354.     i = PyObject_CallMethod(h, "pack", "O", self);
  2355.     data = PyString_AsString(i);
  2356.     length = PyString_Size(i);
  2357.  
  2358.     if (!(i=PyObject_GetAttrString(h, "id")) || (i == Py_None))
  2359.         { PyErr_SetString(PyExc_ValueError, "The resource's .id attribute must be set"); 
  2360.             return NULL; } 
  2361.     else
  2362.         id = PyInt_AsLong(i);
  2363.     if (!(i=PyObject_GetAttrString(h, "type")) || (i == Py_None))
  2364.         { PyErr_SetString(PyExc_ValueError, "The resource's .type attribute must be set"); 
  2365.             return NULL; } 
  2366.     else
  2367.         type = ParseChar4(i);
  2368.     
  2369.     if (pi_file_append_resource(self->pf, data, length, type, id)==-1) {
  2370.         PyErr_SetFromErrno(Error);
  2371.         return NULL;
  2372.     }
  2373.  
  2374.     return Py_BuildValue("");
  2375. }
  2376.  
  2377. static PyObject *
  2378. FileInstall(self, args)
  2379.     PiFileObject *self;
  2380.     PyObject *args;
  2381. {
  2382.     DlpObject *socket;
  2383.     int result;
  2384.     int cardno=0;
  2385.     if (!PyArg_ParseTuple(args, "O!|i", &Dlp_Type, &socket, &cardno))
  2386.         return NULL;
  2387.     
  2388.     if (pi_file_install(self->pf, socket->socket, cardno)==-1) {
  2389.         PyErr_SetFromErrno(Error);
  2390.         return NULL;
  2391.     }
  2392.  
  2393.     return Py_BuildValue("");
  2394. }
  2395.  
  2396. static PyObject *
  2397. FileRetrieve(self, args)
  2398.     PiFileObject *self;
  2399.     PyObject *args;
  2400. {
  2401.     DlpObject *socket;
  2402.     int result;
  2403.     int cardno=0;
  2404.     if (!PyArg_ParseTuple(args, "O!|i", &Dlp_Type, &socket, &cardno))
  2405.         return NULL;
  2406.     
  2407.     if (pi_file_retrieve(self->pf, socket->socket, cardno)==-1) {
  2408.         PyErr_SetFromErrno(Error);
  2409.         return NULL;
  2410.     }
  2411.  
  2412.     return Py_BuildValue("");
  2413. }
  2414.  
  2415.  
  2416. static PyObject *
  2417. FileBlankAppBlock(self, args)
  2418.     PiFileObject *self;
  2419.     PyObject *args;
  2420. {
  2421.     PyObject *ret;
  2422.     PyObject *c, *callargs;
  2423.     if (!PyArg_ParseTuple(args, ""))
  2424.         return NULL;
  2425.     
  2426.     c = PyObject_GetAttrString(self->Class, "AppBlock");
  2427.     callargs = Py_BuildValue("()");
  2428.     ret = PyEval_CallObject(c, callargs);
  2429.     Py_DECREF(callargs);
  2430.     return ret;
  2431. }
  2432.  
  2433. static PyObject *
  2434. FileBlankSortBlock(self, args)
  2435.     PiFileObject *self;
  2436.     PyObject *args;
  2437. {
  2438.     PyObject *ret;
  2439.     PyObject *c, *callargs;
  2440.     if (!PyArg_ParseTuple(args, ""))
  2441.         return NULL;
  2442.     
  2443.     c = PyObject_GetAttrString(self->Class, "SortBlock");
  2444.     callargs = Py_BuildValue("()");
  2445.     ret = PyEval_CallObject(c, callargs);
  2446.     Py_DECREF(callargs);
  2447.     return ret;
  2448. }
  2449.  
  2450. static PyObject *
  2451. FileBlankRecord(self, args)
  2452.     PiFileObject *self;
  2453.     PyObject *args;
  2454. {
  2455.     PyObject *ret;
  2456.     PyObject *c, *callargs;
  2457.     if (!PyArg_ParseTuple(args, ""))
  2458.         return NULL;
  2459.     
  2460.     c = PyObject_GetAttrString(self->Class, "Record");
  2461.     callargs = Py_BuildValue("()");
  2462.     ret = PyEval_CallObject(c, callargs);
  2463.     Py_DECREF(callargs);
  2464.     return ret;
  2465. }
  2466.  
  2467. static PyObject *
  2468. FileBlankResource(self, args)
  2469.     PiFileObject *self;
  2470.     PyObject *args;
  2471. {
  2472.     PyObject *ret;
  2473.     PyObject *c, *callargs;
  2474.     if (!PyArg_ParseTuple(args, ""))
  2475.         return NULL;
  2476.     
  2477.     c = PyObject_GetAttrString(self->Class, "Resource");
  2478.     callargs = Py_BuildValue("()");
  2479.     ret = PyEval_CallObject(c, callargs);
  2480.     Py_DECREF(callargs);
  2481.     return ret;
  2482. }
  2483.  
  2484. static PyObject *
  2485. MemoUnpack(self, args)
  2486.     PyObject *self;
  2487.     PyObject *args;
  2488. {
  2489.     struct Memo m;
  2490.  
  2491.     char * data;
  2492.     int length;
  2493.     PyObject * result, *dict;
  2494.     
  2495.     if (!PyArg_ParseTuple(args, "Os#", &dict, &data, &length))
  2496.         return NULL;
  2497.     
  2498.     unpack_Memo(&m, data, length);
  2499.     
  2500.     PyDict_SetItemString(dict, "text", PyString_FromString(m.text));
  2501.     
  2502.     free_Memo(&m);
  2503.     
  2504.     Py_INCREF(Py_None);
  2505.     return Py_None;
  2506. }
  2507.  
  2508. static PyObject *
  2509. MemoPack(self, args)
  2510.     PyObject *self;
  2511.     PyObject *args;
  2512. {
  2513.     char * data;
  2514.     int length;
  2515.     struct Memo m;
  2516.     PyObject *dict, *result, *e;
  2517.     
  2518.     if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))
  2519.         return NULL;
  2520.     
  2521.     data = malloc(0xffff);
  2522.     memset(&m, 0, sizeof(m));
  2523.     
  2524.     m.text = (e=PyDict_GetItemString(dict, "text")) ? PyString_AsString(e) : 0;
  2525.     
  2526.     length = pack_Memo(&m, data, 0xffff);
  2527.     
  2528.     result = Py_BuildValue("s#", data, length);
  2529.     
  2530.     free(data);
  2531.     return result;
  2532. }
  2533.  
  2534. static void doUnpackCategory(PyObject * dict, struct CategoryAppInfo * c)
  2535. {
  2536.     int i;
  2537.     PyObject * names, *ids, *renames;
  2538.     names = PyList_New(16);
  2539.     for (i=0;i<16;i++)
  2540.         PyList_SetItem(names, i, PyString_FromString(c->name[i]));
  2541.  
  2542.     ids = PyList_New(16);
  2543.     for (i=0;i<16;i++)
  2544.         PyList_SetItem(ids, i, PyInt_FromLong(c->ID[i]));    
  2545.  
  2546.     renames = PyList_New(16);
  2547.     for (i=0;i<16;i++)
  2548.         PyList_SetItem(renames, i, PyInt_FromLong(c->renamed[i]));    
  2549.         
  2550.     PyDict_SetItemString(dict, "categoryName", names);
  2551.     PyDict_SetItemString(dict, "categoryID", ids);
  2552.     PyDict_SetItemString(dict, "categoryRenamed", renames);
  2553.     PyDict_SetItemString(dict, "categoryLastUniqueID", PyInt_FromLong(c->lastUniqueID));
  2554. }
  2555.  
  2556. static void doPackCategory(PyObject * dict, struct CategoryAppInfo * c)
  2557. {
  2558.     int i;
  2559.     PyObject *e, *s;
  2560.     
  2561.     i = 0;
  2562.     if (e=PyDict_GetItemString(dict, "categoryName")) {
  2563.         for(i=0;i<16;i++) {
  2564.             s = PyList_GetItem(e, i);
  2565.             if (s)
  2566.                 strcpy(c->name[i], PyString_AsString(s));
  2567.             else
  2568.                 break;
  2569.         }
  2570.     }
  2571.     for(;i<16;i++)
  2572.         c->name[i][0] = '\0';
  2573.  
  2574.     i = 0;
  2575.     if (e=PyDict_GetItemString(dict, "categoryID")) {
  2576.         for(i=0;i<16;i++) {
  2577.             s = PyList_GetItem(e, i);
  2578.             if (s)
  2579.                 c->ID[i] = PyInt_AsLong(s);
  2580.             else
  2581.                 break;
  2582.         }
  2583.     }
  2584.     for(;i<16;i++)
  2585.         c->ID[i] = 0;
  2586.  
  2587.     i = 0;
  2588.     if (e=PyDict_GetItemString(dict, "categoryRenamed")) {
  2589.         for(i=0;i<16;i++) {
  2590.             s = PyList_GetItem(e, i);
  2591.             if (s)
  2592.                 c->renamed[i] = PyInt_AsLong(s);
  2593.             else
  2594.                 break;
  2595.         }
  2596.     }
  2597.     for(;i<16;i++)
  2598.         c->renamed[i] = 0;
  2599.  
  2600.     c->lastUniqueID = (e=PyDict_GetItemString(dict, "categoryLastUniqueID")) ? PyInt_AsLong(e) : 0;
  2601. }    
  2602.  
  2603. static PyObject *
  2604. MemoUnpackAppBlock(self, args)
  2605.     PyObject *self;
  2606.     PyObject *args;
  2607. {
  2608.     char * data;
  2609.     int length;
  2610.     PyObject *names, *ids, *h, *raw, *dict;
  2611.     struct MemoAppInfo m;
  2612.     int i;
  2613.     
  2614.     if (!PyArg_ParseTuple(args, "Os#", &dict, &data, &length))
  2615.         return NULL;
  2616.     
  2617.     unpack_MemoAppInfo(&m, data, length);
  2618.  
  2619.  
  2620.     doUnpackCategory(dict, &m.category);
  2621.  
  2622.     PyDict_SetItemString(dict, "sortByAlpha", PyInt_FromLong(m.sortByAlpha));
  2623.     
  2624.     Py_INCREF(Py_None);
  2625.     return Py_None;
  2626. }
  2627.  
  2628. static PyObject *
  2629. MemoPackAppBlock(self, args)
  2630.     PyObject *self;
  2631.     PyObject *args;
  2632. {
  2633.     char * data;
  2634.     int length;
  2635.     PyObject *names, *ids;
  2636.     struct MemoAppInfo m;
  2637.     int i;
  2638.     PyObject *dict, *e, *c, *result;
  2639.  
  2640.     if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))
  2641.         return NULL;
  2642.     
  2643.     data = calloc(0xFFFF, 1);
  2644.     memset(&m, 0, sizeof(m));
  2645.  
  2646.     doPackCategory(dict, &m.category);
  2647.  
  2648.     m.sortByAlpha = (e=PyDict_GetItemString(dict, "sortByAlpha")) ? PyInt_AsLong(e) : 0;
  2649.     
  2650.     length = pack_MemoAppInfo(&m, data, 0xffff);
  2651.     
  2652.     result = Py_BuildValue("s#", data, length);
  2653.     free(data);
  2654.     
  2655.     fprintf(stderr,"Returning from MemoPackAppBlock\n");
  2656.     return result;
  2657. }
  2658.  
  2659. static PyObject *
  2660. TodoUnpack(self, args)
  2661.     PyObject *self;
  2662.     PyObject *args;
  2663. {
  2664.     char * data;
  2665.     int length;
  2666.     struct ToDo m;
  2667.     PyObject * result, *dict;
  2668.     
  2669.     if (!PyArg_ParseTuple(args, "Os#", &dict, &data, &length))
  2670.         return NULL;
  2671.     
  2672.     unpack_ToDo(&m, data, length);
  2673.     
  2674.     PyDict_SetItemString(dict, "due", m.indefinite ? Py_BuildValue("") : BuildTm(&m.due));
  2675.     PyDict_SetItemString(dict, "priority", PyInt_FromLong(m.priority));
  2676.     PyDict_SetItemString(dict, "complete", PyInt_FromLong(m.complete));
  2677.     PyDict_SetItemString(dict, "description", m.description ? PyString_FromString(m.description) : Py_BuildValue(""));
  2678.     PyDict_SetItemString(dict, "note", m.note ? PyString_FromString(m.note) : Py_BuildValue(""));
  2679.     
  2680.     /*result = Py_BuildValue("{sOsisiszsz}", 
  2681.         "due", ,
  2682.         "priority",m.priority,
  2683.         "complete",m.complete,
  2684.         "description", m.description,
  2685.         "note", m.note
  2686.         );*/
  2687.     
  2688.     free_ToDo(&m);
  2689.     
  2690.     return Py_BuildValue("");
  2691. }
  2692.  
  2693. static PyObject *
  2694. TodoPack(self, args)
  2695.     PyObject *self;
  2696.     PyObject *args;
  2697. {
  2698.     char * data;
  2699.     int length;
  2700.     struct ToDo m;
  2701.     PyObject * dict, *e, *o;
  2702.     
  2703.     if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict))
  2704.         return NULL;
  2705.     
  2706.     data = malloc(0xffff);
  2707.  
  2708.     m.description = (e=PyDict_GetItemString(o, "description")) ? PyString_AsString(e) : 0;
  2709.     m.note = (e=PyDict_GetItemString(o, "note")) ? PyString_AsString(e) : 0;
  2710.     m.complete = (e=PyDict_GetItemString(o, "complete")) ? PyInt_AsLong(e) : 0;
  2711.     m.priority = (e=PyDict_GetItemString(o, "priority")) ? PyInt_AsLong(e) : 0;
  2712.     m.indefinite = 1;
  2713.     memset(&m.due, '\0', sizeof(struct tm));
  2714.     if (e=PyDict_GetItemString(o, "due"))
  2715.         if (PyTuple_Check(e)) {
  2716.             ParseTm(e, &m.due);
  2717.             m.indefinite=0;
  2718.         }
  2719.     
  2720.     length = pack_ToDo(&m, data, 0xffff);
  2721.     
  2722.     o = Py_BuildValue("s#", data, length);
  2723.     free(data);
  2724.     
  2725.     return o;
  2726. }
  2727.  
  2728. static PyObject *
  2729. TodoUnpackAppBlock(self, args)
  2730.     PyObject *self;
  2731.     PyObject *args;
  2732. {
  2733.     char * data;
  2734.     int length;
  2735.     PyObject *names, *ids, *dict;
  2736.     struct ToDoAppInfo m;
  2737.     int i;
  2738.     
  2739.     if (!PyArg_ParseTuple(args, "Os#", &dict, &data, &length))
  2740.         return NULL;
  2741.     
  2742.     unpack_ToDoAppInfo(&m, data, length);
  2743.     
  2744.     PyDict_SetItemString(dict, "sortByPriority", PyInt_FromLong(m.sortByPriority));
  2745.     PyDict_SetItemString(dict, "dirty", PyInt_FromLong(m.dirty));
  2746.  
  2747.     doUnpackCategory(dict, &m.category);
  2748.     
  2749.     return Py_BuildValue("");
  2750. }
  2751.  
  2752. static PyObject *
  2753. TodoPackAppBlock(self, args)
  2754.     PyObject *self;
  2755.     PyObject *args;
  2756. {
  2757.     char * data;
  2758.     int length;
  2759.     PyObject *names, *ids;
  2760.     struct ToDoAppInfo m;
  2761.     int i;
  2762.     PyObject *result, *o, *e, *c;
  2763.     
  2764.     if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &o))
  2765.         return NULL;
  2766.     
  2767.     data = malloc(0xFFFF);
  2768.     
  2769.     m.sortByPriority = (e=PyDict_GetItemString(o, "sortByPriority")) ? PyInt_AsLong(e) : 0;
  2770.     m.dirty = (e=PyDict_GetItemString(o, "dirty")) ? PyInt_AsLong(e) : 0;
  2771.  
  2772.     doPackCategory(o, &m.category);
  2773.     
  2774.     length = pack_ToDoAppInfo(&m, data, 0xffff);
  2775.     
  2776.     result = Py_BuildValue("s#", data, length);
  2777.     
  2778.     free(data);
  2779.     return result;
  2780. }
  2781.  
  2782. static PyObject *
  2783. MailUnpackPref(self, args)
  2784.     PyObject *self;
  2785.     PyObject *args;
  2786. {
  2787.  
  2788.     char * data;
  2789.     int length;
  2790.     int id;
  2791.     PyObject * result, *dict;
  2792.     
  2793.     if (!PyArg_ParseTuple(args, "Os#i", &dict, &data, &length, &id))
  2794.         return NULL;
  2795.         
  2796.     if( (id == 1)  || (id==2)) {
  2797.         struct MailSyncPref m;
  2798.         unpack_MailSyncPref(&m, data, length);
  2799.         
  2800.         PyDict_SetItemString(dict, "syncType", PyInt_FromLong(m.syncType));
  2801.         PyDict_SetItemString(dict, "getGigh", PyInt_FromLong(m.getHigh));
  2802.         PyDict_SetItemString(dict, "getContaining", PyInt_FromLong(m.getContaining));
  2803.         PyDict_SetItemString(dict, "truncate", PyInt_FromLong(m.truncate));
  2804.         PyDict_SetItemString(dict, "filterTo", Py_BuildValue("z", m.filterTo));
  2805.         PyDict_SetItemString(dict, "filterFrom", Py_BuildValue("z", m.filterFrom));
  2806.         PyDict_SetItemString(dict, "filterSubject", Py_BuildValue("z", m.filterSubject));
  2807.     
  2808.         free_MailSyncPref(&m);
  2809.     } else if (id == 3) {
  2810.         PyDict_SetItemString(dict, "signature", PyString_FromString(data));
  2811.     }
  2812.     
  2813.     Py_INCREF(Py_None);
  2814.     return Py_None;
  2815. }
  2816.  
  2817. static PyObject *
  2818. MailPackPref(self, args)
  2819.     PyObject *self;
  2820.     PyObject *args;
  2821. {
  2822.     char * data;
  2823.     int length;
  2824.     int id;
  2825.     PyObject *dict, *result, *e;
  2826.     
  2827.     if (!PyArg_ParseTuple(args, "O!i", &PyDict_Type, &dict, &id))
  2828.         return NULL;
  2829.         
  2830.     data = 0;
  2831.     length = 0;
  2832.     
  2833.     if (id == 3) {
  2834.         e = PyDict_GetItemString(dict, "signature");
  2835.         if (e) 
  2836.             length = PyString_Size(e); 
  2837.         data = malloc(length+1);
  2838.         if (length)
  2839.             memcpy(data, PyString_AsString(e), length);
  2840.         data[length] = 0;
  2841.         length++;
  2842.     }
  2843.     else if ((id == 1) || (id==2)) {
  2844.         struct MailSyncPref m;
  2845.     
  2846.         data = malloc(0xffff);
  2847.         memset(&m, 0, sizeof(m));
  2848.     
  2849.         m.syncType = PyInt_AsLong(PyDict_GetItemString(dict, "syncType"));
  2850.         m.getHigh = PyInt_AsLong(PyDict_GetItemString(dict, "getHigh"));
  2851.         m.getContaining = PyInt_AsLong(PyDict_GetItemString(dict, "getContaining"));
  2852.         m.truncate = PyInt_AsLong(PyDict_GetItemString(dict, "truncate"));
  2853.         m.filterTo = PyString_AsString(PyDict_GetItemString(dict, "filterTo"));
  2854.         m.filterFrom = PyString_AsString(PyDict_GetItemString(dict, "filterFrom"));
  2855.         m.filterSubject = PyString_AsString(PyDict_GetItemString(dict, "filterSubject"));
  2856.     
  2857.         length = pack_MailSyncPref(&m, data, 0xffff);
  2858.     }
  2859.     else {
  2860.         e = PyDict_GetItemString(dict, "raw");
  2861.         Py_XINCREF(e);
  2862.         return e;
  2863.     }
  2864.     
  2865.     
  2866.     result = Py_BuildValue("s#", data, length);
  2867.     
  2868.     if (data)    
  2869.         free(data);
  2870.  
  2871.     return result;
  2872. }
  2873.  
  2874.  
  2875. static PyObject *
  2876. RPCPack(self, args)
  2877.     PyObject *self;
  2878.     PyObject *args;
  2879. {
  2880.     long trap;
  2881.     char * reply;
  2882.     int r;
  2883.     PyObject *rpcargs, *rpctypes;
  2884.     RpcObject * result;
  2885.     int i;
  2886.     
  2887.     if (!PyArg_ParseTuple(args, "lzO!O!", &trap, &reply, &PyTuple_Type, &rpctypes, &PyTuple_Type, &rpcargs))
  2888.         return NULL;
  2889.  
  2890.  
  2891.     if (PyTuple_Size(rpcargs) != PyTuple_Size(rpctypes)) {
  2892.         PyErr_SetString(Error, "types and arguments must match");
  2893.         return NULL;
  2894.     }
  2895.  
  2896.     for(i=0;i<PyList_Size(rpcargs);i++) {
  2897.         PyObject * type = PyTuple_GetItem(rpctypes, i);
  2898.         PyObject * value = PyTuple_GetItem(rpcargs, i);
  2899.         if (!PyString_Check(type)) {
  2900.             PyErr_SetString(Error, "type must be string");
  2901.             return NULL;
  2902.         } else if (!PyInt_Check(value) && !PyString_Check(value)) {
  2903.             PyErr_SetString(Error, "argument must be string or integer");
  2904.             return NULL;
  2905.         }
  2906.     }
  2907.     
  2908.     result = PyObject_NEW(RpcObject, &Rpc_Type);
  2909.     result->p = malloc(sizeof(struct RPC_params));
  2910.     /*result->rpcargs = rpcargs;
  2911.     Py_INCREF(rpcargs);*/
  2912.  
  2913.     result->p->trap = trap;
  2914.     
  2915.     if ((reply == 0) || (strlen(reply)==0))
  2916.         r = RPC_NoReply;
  2917.     else
  2918.         switch (reply[0]) {
  2919.             case 'i': case 'l': case 's': case 'b': case 'c':
  2920.                 r = RPC_IntReply;
  2921.                 break;
  2922.             case 'p': case 'h': case '*': case '&':
  2923.                 r = RPC_PtrReply;
  2924.                 break;
  2925.             default:
  2926.                 r = RPC_NoReply;
  2927.         }
  2928.         
  2929.     result->p->reply = r;
  2930.     for(i=0;i<PyTuple_Size(rpcargs);i++) {
  2931.         char * type = PyString_AsString(PyTuple_GetItem(rpctypes, i));
  2932.         PyObject * value = PyTuple_GetItem(rpcargs, i);
  2933.         char * data = 0;
  2934.         int len = 0;
  2935.         unsigned long arg;
  2936.         int ref=0;
  2937.         if (type[0] == '&') {
  2938.             result->p->param[i].byRef = 1;    
  2939.             type++;
  2940.         } else 
  2941.             result->p->param[i].byRef = 0;    
  2942.         result->p->param[i].invert = 0;
  2943.         result->p->param[i].data = &result->p->param[i].arg;
  2944.  
  2945.         switch(type[0]) {
  2946.         case '*': case 'p':
  2947.             result->p->param[i].data = malloc(PyString_Size(value)+1);
  2948.             memcpy(result->p->param[i].data, PyString_AsString(value), PyString_Size(value)+1);
  2949.             result->p->param[i].size = PyString_Size(value);
  2950.             result->p->param[i].invert = 0;
  2951.             break;
  2952.         case 'b': case 'c':
  2953.             result->p->param[i].arg = PyInt_AsLong(value);
  2954.             result->p->param[i].size = 2;
  2955.             result->p->param[i].invert = 2;
  2956.             break;
  2957.         case 's':
  2958.             result->p->param[i].arg = PyInt_AsLong(value);
  2959.             result->p->param[i].size = 2;
  2960.             result->p->param[i].invert = 1;
  2961.             break;
  2962.         case 'i': case 'l': 
  2963.             result->p->param[i].arg = PyInt_AsLong(value);
  2964.             result->p->param[i].size = 4;
  2965.             result->p->param[i].invert = 1;
  2966.             break;
  2967.         }
  2968.     }
  2969.     result->p->args = i;
  2970.     
  2971.     return (PyObject*)result;
  2972. }
  2973.  
  2974. static PyObject *
  2975. DlpRPC(self, args)
  2976.     DlpObject *self;
  2977.     PyObject *args;
  2978. {
  2979.     long trap;
  2980.     char * reply;
  2981.     int r;
  2982.     RpcObject * rpc;
  2983.     int i;
  2984.     int err;
  2985.     long result;
  2986.     PyObject * out;
  2987.     
  2988.     if (!PyArg_ParseTuple(args, "O!", &Rpc_Type, &rpc))
  2989.         return NULL;
  2990.     
  2991.     err = dlp_RPC(self->socket, rpc->p, &result);
  2992.  
  2993.     out = PyTuple_New(rpc->p->args);
  2994.     
  2995.     for(i=0;i<rpc->p->args;i++) {
  2996.         struct RPC_param * p = &rpc->p->param[i];
  2997.         if (p->invert == 0) {
  2998.             PyTuple_SetItem(out, i, PyString_FromStringAndSize(p->data,p->size));
  2999.         } else {
  3000.             PyTuple_SetItem(out, i, PyInt_FromLong(p->arg));
  3001.         }
  3002.     }
  3003.     
  3004.     return Py_BuildValue("(liO)", result, err, out);
  3005. }
  3006.  
  3007. static PyMethodDef PiFile_methods[] = {
  3008.     {"getRecords",    FileRecords, 1},
  3009.     {"checkID",    FileCheckID, 1},
  3010.     {"getRecord",    FileGetRec, 1},
  3011.     {"getRecordByID",    FileGetRecById, 1},
  3012.     {"getResource",    FileGetRsc, 1},
  3013.     {"addRecord",    FileAddRec, 1},
  3014.     {"addResource",    FileAddRsc, 1},
  3015.     {"getAppBlock",    FileGetAppBlock, 1},
  3016.     {"setAppBlock",    FileGetAppBlock, 1},
  3017.     {"getSortBlock",FileGetSortBlock, 1},
  3018.     {"setSortBlock",FileSetSortBlock, 1},
  3019.     {"getDBInfo",    FileGetDBInfo, 1},
  3020.     {"setDBInfo",    FileSetDBInfo, 1},
  3021.     {"install",    FileInstall, 1},
  3022.     {"retrieve",    FileRetrieve, 1},
  3023.     {"close",    FileClose, 1},
  3024.     {"newAppBlock", FileBlankAppBlock, 1},
  3025.     {"newSortBlock", FileBlankSortBlock, 1},
  3026.     {"newRecord", FileBlankRecord, 1},
  3027.     {"newResource", FileBlankResource, 1},
  3028.     {NULL,    NULL}
  3029. };
  3030.  
  3031. static PyMethodDef Dlp_methods[] = {
  3032.     {"open",    OpenDB, 1},
  3033.     {"create",    CreateDB, 1},
  3034.     {"delete",    DeleteDB, 1},
  3035.     {"status",    Status, 1},
  3036.     {"dirty",    Dirty, 1},
  3037.     {"getBattery",    Battery, 1},
  3038.     {"reset",    ResetSystem, 1},
  3039.     {"close",    Close, 1},
  3040.     {"abort",    Abort, 1},
  3041.     {"log",        Log, 1},
  3042.     {"getTime",    GetTime, 1},
  3043.     {"setTime",    GetTime, 1},
  3044.     {"getCardInfo",    CardInfo, 1},
  3045.     {"getSysInfo",    SysInfo, 1},
  3046.     {"getUserInfo",    GetUserInfo, 1},
  3047.     {"setUserInfo",    SetUserInfo, 1},
  3048.     {"getPref",    GetAppPref, 1},
  3049.     {"newPref",    BlankAppPref, 1},
  3050.     {"setPref",    SetAppPref, 1},
  3051.     {"getPrefRaw",    GetAppPrefRaw, 1},
  3052.     {"setPrefRaw",    SetAppPrefRaw, 1},
  3053.     {"getFeature",    GetFeature, 1},
  3054.     {"getDBInfo",    GetDBInfo, 1},
  3055.     {"findDBInfo",    FindDBInfo, 1},
  3056.     {"callApplication",    CallApp, 1},
  3057.     {"RPC",        DlpRPC, 1},
  3058.     {NULL,    NULL}
  3059. };
  3060.  
  3061. static PyMethodDef DlpDB_methods[] = {
  3062.     {"setRecord",    SetRec, 1},
  3063.     {"setResource",    SetRsc, 1},
  3064.     {"getNextRecord",    NextCatRec, 1},
  3065.     {"getNextModRecord",    NextModRec, 1},
  3066.     {"getResource",    GetRsc, 1},
  3067.     {"getResourceByID",    GetRscById, 1},
  3068.     {"getRecord",    GetRec, 1},
  3069.     {"getRecordByID",    GetRecById, 1},
  3070.     {"deleteRecord",    DeleteRec, 1},
  3071.     {"deleteRecords",    DeleteAllRec, 1},
  3072.     {"deleteResource",    DeleteRsc, 1},
  3073.     {"deleteResources",    DeleteAllRsc, 1},
  3074.     {"close",    CloseDB, 1},
  3075.     {"getRecords",    Records, 1},
  3076.     {"getRecordIDs",    RecordIDs, 1},
  3077.     {"getAppBlock",    GetAppBlock, 1},
  3078.     {"setAppBlock",    SetAppBlock, 1},
  3079.     {"getSortBlock",GetSortBlock, 1},
  3080.     {"setSortBlock",SetSortBlock, 1},
  3081.     {"moveCategory",MoveCategory, 1},
  3082.     {"deleteCategory",DeleteCategory, 1},
  3083.     {"purge",    Purge, 1},
  3084.     {"resetNext",    ResetNext, 1},
  3085.     {"resetFlags",    ResetFlags, 1},
  3086.     {"newAppBlock", BlankAppBlock, 1},
  3087.     {"newSortBlock", BlankSortBlock, 1},
  3088.     {"newRecord", BlankRecord, 1},
  3089.     {"newResource", BlankResource, 1},
  3090.     {"getPref",    DBGetAppPref, 1},
  3091.     {"newPref",    DBBlankAppPref, 1},
  3092.     {"setPref",    DBSetAppPref, 1},
  3093. /*    {"setPrefRaw",    DBGetAppPrefRaw, 1},
  3094.     {"setPrefRaw",    DBSetAppPrefRaw, 1},*/
  3095.     {NULL,    NULL}
  3096. };
  3097.  
  3098.  
  3099.  
  3100. static PyMethodDef Methods[] = {
  3101.     {"socket",    Socket, 1},
  3102.     {"bind",    Bind, 1},
  3103.     {"read",    Read, 1},
  3104.     {"write",    Write, 1},
  3105.     {"accept",    Accept, 1},
  3106.     {"close",    CloseSocket, 1},
  3107.     {"listen",    Listen, 1},
  3108.     {"fileOpen",    OpenFile, 1},
  3109.     {"fileCreate",    CreateFile, 1},
  3110.     {"openPort",    OpenPort, 1},
  3111.     {"MemoUnpack",    MemoUnpack, 1},
  3112.     {"MemoUnpackAppBlock",    MemoUnpackAppBlock, 1},
  3113.     {"MemoPack",    MemoPack, 1},
  3114.     {"MemoPackAppBlock",    MemoPackAppBlock, 1},
  3115.     {"ToDoUnpack",    TodoUnpack, 1},
  3116.     {"ToDoUnpackAppBlock",    TodoUnpackAppBlock, 1},
  3117.     {"ToDoPack",    TodoPack, 1},
  3118.     {"ToDoPackAppBlock",    TodoPackAppBlock, 1},
  3119.     {"MailUnpackPref",    MailUnpackPref, 1},
  3120.     {"MailPackPref",    MailPackPref, 1},
  3121.     {"PackRPC",    RPCPack, 1},
  3122.     {NULL, NULL}
  3123. };
  3124.  
  3125. static PyMethodDef MemoAppBlock_methods[] = {
  3126.     {"unpack",    MemoUnpackAppBlock, 1},
  3127.     {NULL, NULL}
  3128. };
  3129.  
  3130.  
  3131. #define SetDictInt(string,ch) \
  3132.         PyDict_SetItemString(d,string,PyInt_FromLong((long) (ch)));
  3133.  
  3134. void
  3135. init_pdapilot()
  3136. {
  3137.     PyObject *m, *d, *main, *t;
  3138.     main = m = Py_InitModule("_pdapilot", Methods);
  3139.     d = PyModule_GetDict(m);
  3140.     Error = PyString_FromString("pdapilot.error");
  3141.     PyDict_SetItemString(d, "error", Error);
  3142.     
  3143.     DBClasses = PyDict_New();
  3144.     PyDict_SetItemString(d, "DBClasses", DBClasses);
  3145.  
  3146.     PrefClasses = PyDict_New();
  3147.     PyDict_SetItemString(d, "PrefClasses", PrefClasses);
  3148.  
  3149.     SetDictInt("PI_AF_SLP", PI_AF_SLP);
  3150.  
  3151.     SetDictInt("PI_PF_SLP", PI_PF_SLP);
  3152.     SetDictInt("PI_PF_PADP", PI_PF_PADP);
  3153.     SetDictInt("PI_PF_LOOP", PI_PF_LOOP);
  3154.  
  3155.     SetDictInt("PI_SOCK_STREAM", PI_SOCK_STREAM);
  3156.     SetDictInt("PI_SOCK_DGRAM", PI_SOCK_DGRAM);
  3157.     SetDictInt("PI_SOCK_RAW", PI_SOCK_RAW);
  3158.     SetDictInt("PI_SOCK_SEQPACKET", PI_SOCK_SEQPACKET);
  3159.  
  3160.     SetDictInt("PI_PilotSocketDLP", PI_PilotSocketDLP);
  3161.     SetDictInt("PI_PilotSocketConsole", PI_PilotSocketConsole);
  3162.     SetDictInt("PI_PilotSocketDebugger", PI_PilotSocketDebugger);
  3163.     SetDictInt("PI_PilotSockerRemoteUI", PI_PilotSocketRemoteUI);    
  3164.  
  3165.     SetDictInt("DBResource", dlpDBFlagResource);
  3166.     SetDictInt("DBReadOnly", dlpDBFlagReadOnly);
  3167.     SetDictInt("DBAppBlockDirty", dlpDBFlagAppInfoDirty);
  3168.     SetDictInt("DBBackup", dlpDBFlagBackup);
  3169.     SetDictInt("DBOpen", dlpDBFlagOpen);
  3170.     SetDictInt("DBNew", dlpDBFlagNewer);
  3171.     SetDictInt("DBReset", dlpDBFlagReset);
  3172.     
  3173.     SetDictInt("OpenDBRead", dlpOpenRead);
  3174.     SetDictInt("OpenDBWrite", dlpOpenWrite);
  3175.     SetDictInt("OpenDBReadWrite", dlpOpenReadWrite);
  3176.     SetDictInt("OpenDBExclusive", dlpOpenExclusive);
  3177.     SetDictInt("OpenDBSecret", dlpOpenSecret);
  3178.  
  3179.     SetDictInt("EndNormal", dlpEndCodeNormal);
  3180.     SetDictInt("EndMemory", dlpEndCodeOutOfMemory);
  3181.     SetDictInt("EndCancelled", dlpEndCodeUserCan);
  3182.     SetDictInt("EndOther", dlpEndCodeOther);
  3183.     
  3184.     SetDictInt("RecDeleted", dlpRecAttrDeleted);
  3185.     SetDictInt("RecDirty", dlpRecAttrDirty);
  3186.     SetDictInt("RecBusy", dlpRecAttrBusy);
  3187.     SetDictInt("RecSecret", dlpRecAttrSecret);
  3188.     SetDictInt("RecArchived", dlpRecAttrArchived);
  3189.  
  3190. }
  3191.